疯狂的提子 发表于 2013-1-4 02:19:00

学习Nop中Routes的使用

<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("favicon.ico");            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");                        //register custom routes (plugins, etc)            var routePublisher = EngineContext.Current.Resolve<IRoutePublisher>();            routePublisher.RegisterRoutes(routes);                        routes.MapRoute(                "Default", // Route name                "{controller}/{action}/{id}", // URL with parameters                new { controller = "Home", action = "Index", id = UrlParameter.Optional },                new[] { "Nop.Web.Controllers" }            );      }
页: [1]
查看完整版本: 学习Nop中Routes的使用