|
|
<div id="cnblogs_post_body">1. 映射路由
大型MVC项目为了扩展性,可维护性不能向一般项目在Global中RegisterRoutes的方法里面映射路由。这里学习一下Nop是如何做的。
 
Global.cs  . 通过IOC容器取得IRoutePublisher实例
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 5px; background-color: #f5f5f5; padding-left: 5px; padding-right: 5px; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 5px" class="cnblogs_code"> public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute(&quot;favicon.ico&quot;); routes.IgnoreRoute(&quot;{resource}.axd/{*pathInfo}&quot;); //register custom routes (plugins, etc) var routePublisher = EngineContext.Current.Resolve<IRoutePublisher>(); routePublisher.RegisterRoutes(routes); routes.MapRoute( &quot;Default&quot;, // Route name &quot;{controller}/{action}/{id}&quot;, // URL with parameters new { controller = &quot;Home&quot;, action = &quot;Index&quot;, id = UrlParameter.Optional }, new[] { &quot;Nop.Web.Controllers&quot; } ); } |
|