C# 路由系统使用默认路由而不是特定路由
我的mvc应用程序中存在路由问题。我的核心应用程序带有ProductsController和扩展,加载在“PreApplicationStartMethod”中。在本扩展中,我按如下方式注册路由:C# 路由系统使用默认路由而不是特定路由,c#,asp.net,.net,asp.net-mvc,C#,Asp.net,.net,Asp.net Mvc,我的mvc应用程序中存在路由问题。我的核心应用程序带有ProductsController和扩展,加载在“PreApplicationStartMethod”中。在本扩展中,我按如下方式注册路由: routes.MapRoute( name: "ProductDetails", url: "Products/Details/{id}", defaults: new { controller = "StandardProductsDetails", action = "De
routes.MapRoute(
name: "ProductDetails",
url: "Products/Details/{id}",
defaults: new { controller = "StandardProductsDetails", action = "Details" },
namespaces: new []{ "Shop.Controllers" }
);
在我的核心应用程序中,我没有为ProductsController注册特定路线,但我有一个常规路线:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "Shop.Controllers" }
);
现在,当我在web浏览器中输入/Products/Details/1时,我会重定向到ProductsController
添加路由的顺序是先具体后一般。我已经检查了routes表,其中有我的路由。我认为您在这里使用了两个项目,如果您正在使用,则将该项目作为要首先点击的启动项目(通过右键单击)。如果您在默认路由之前复制路由,而不是在
PreApplicationStartMethod
中注册,会发生什么?我怀疑此事件在管道中发生得太早(在编译App\u code
中的代码之前发生),因此它对注册路由很有用。