搜索

NopCommerce的路由


发布时间: 2022-11-24 22:11:01    浏览次数:30 次

在上节讲到了NopCommerce启动程序Global.asax中

protected void Application_Start()
{
//most of API providers require TLS 1.2 nowadays
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

//disable "X-AspNetMvc-Version" header name
MvcHandler.DisableMvcResponseHeader = true;

//initialize engine context
EngineContext.Initialize(false);

bool databaseInstalled = DataSettingsHelper.DatabaseIsInstalled();
if (databaseInstalled)
{
//remove all view engines
ViewEngines.Engines.Clear();
//except the themeable razor view engine we use
ViewEngines.Engines.Add(new ThemeableRazorViewEngine());
}

//Add some functionality on top of the default ModelMetadataProvider
ModelMetadataProviders.Current = new NopMetadataProvider();

//Registering some regular mvc stuff
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);

...

而RegisterRoutes的定义为:

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" }
);
}

 

通过系统中的IRouteProvider提供具体的路由,具体实现为Nop.Web.Infrastructure中RouteProvider.cs和GenericUrlRouteProvider,cs

其中 GenericUrlRouteProvider内容:

public partial class GenericUrlRouteProvider : IRouteProvider
{
public void RegisterRoutes(RouteCollection routes)
{
//generic URLs
routes.MapGenericPathRoute("GenericUrl",
"{generic_se_name}",
new {controller = "Common", action = "GenericUrl"},
new[] {"Nop.Web.Controllers"});

//define this routes to use in UI views (in case if you want to customize some of them later)
routes.MapLocalizedRoute("Product",
"{SeName}",
new { controller = "Product", action = "ProductDetails" },
new[] {"Nop.Web.Controllers"});

routes.MapLocalizedRoute("Category",
"{SeName}",
new { controller = "Catalog", action = "Category" },
new[] { "Nop.Web.Controllers" });

routes.MapLocalizedRoute("Manufacturer",
"{SeName}",
new { controller = "Catalog", action = "Manufacturer" },
new[] { "Nop.Web.Controllers" });

routes.MapLocalizedRoute("Vendor",
"{SeName}",
new { controller = "Catalog", action = "Vendor" },
new[] { "Nop.Web.Controllers" });

routes.MapLocalizedRoute("NewsItem",
"{SeName}",
new { controller = "News", action = "NewsItem" },
new[] { "Nop.Web.Controllers" });

routes.MapLocalizedRoute("BlogPost",
"{SeName}",
new { controller = "Blog", action = "BlogPost" },
new[] { "Nop.Web.Controllers" });

routes.MapLocalizedRoute("Topic",
"{SeName}",
new { controller = "Topic", action = "TopicDetails" },
new[] { "Nop.Web.Controllers" });

 

//the last route. it's used when none of registered routes could be used for the current request
//but in this case we cannot process non-registered routes (/controller/action)
//routes.MapLocalizedRoute(
// "PageNotFound-Wildchar",
// "{*url}",
// new { controller = "Common", action = "PageNotFound" },
// new[] { "Nop.Web.Controllers" });
}

 

 

 

免责声明 NopCommerce的路由,资源类别:文本, 浏览次数:30 次, 文件大小:-- , 由本站蜘蛛搜索收录2022-11-24 10:11:01。此页面由程序自动采集,只作交流和学习使用,本站不储存任何资源文件,如有侵权内容请联系我们举报删除, 感谢您对本站的支持。 原文链接:https://www.cnblogs.com/5x19/p/16916373.html