首页 > 其他分享 >NopCommerce的路由

NopCommerce的路由

时间:2022-11-22 20:48:43浏览次数:41  
标签:Web action controller NopCommerce routes new Nop 路由

在上节讲到了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" });
}

 

 

 

标签:Web,action,controller,NopCommerce,routes,new,Nop,路由
From: https://www.cnblogs.com/5x19/p/16916373.html

相关文章