2016-03-02 152 views
0

我的mvc应用中有路由问题。我有我的核心应用程序与ProductsController和扩展在“PreApplicationStartMethod”中加载。在这种extenstion我注册的路线是这样的:路由系统使用默认路由而不是特定的路由

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

现在,当我进入/产品/详情/ 1在Web浏览器im重定向到ProductsController。

添加路线的Oderd是特定的第一个,一般的最后一个。我检查了路线表,并且我的路线存在于其中。

+0

如果您在默认路由之前复制路由而不是在'PreApplicationStartMethod'中注册,会发生什么?我怀疑这个事件发生的过早(每[本帖]](http://haacked.com/archive/2010/05/16/three-hidden-extensibility-gems-in-asp-net-4。 aspx /)发生在编译“App_Code”代码之前),因为它对注册路由很有用。 – NightOwl888

回答

0

我想你在这里使用两个项目,如果你正在使用,然后使项目作为启动项目(通过右击),你想先击中。