Routes.Add和MapRoute有什么区别?

all*_*lan 3 asp.net-mvc asp.net-mvc-routing asp.net-mvc-2

我只使用了MapRoute并稍微想知道Routes.Add的使用位置以及它与MapRoute的不同之处?

Jos*_*osh 8

MapRoute只是更广义的Route.Add()的包装器.确切地说,它是一种扩展方法.

路由不是特定于MVC,因此允许您提供任何合适的路由.这使它非常灵活,允许您实现自己的自定义RouteHandler.我在ASP.Net 3.5中为.aspx页面做了这个.

它看起来像这样:

routes.Add("Blah", 
   Route("custom/{stuff}", new SecretSauceRouteHandler()))
Run Code Online (Sandbox Code Playgroud)