如何在ASP.NET MVC3中路由到/ Configuration / URL?

时间:2011-08-10 17:48:16

标签: asp.net-mvc-3 asp.net-mvc-routing

这适用于ASP.NET MVC3 Web应用程序。在RegisterRoutes中,我有以下作为我唯一的一行:

routes.MapRoute("Default", "Configuration", new { controller = "DeviceConfiguration", action = "Index" });

当我运行项目时,转到URL / Configuration /会给我一个404错误。但是,如果我将配置一词更改为任何其他单词,例如:

routes.MapRoute("Default", "Configuratio", new { controller = "DeviceConfiguration", action = "Index" });

然后转到URL / Configuratio /加载就好了。似乎ASP.NET只是拒绝路由到URL / Configuration /.

同样,这是RegisterRoutes中唯一的一行;我已经尝试评论其他一切来调试这个。我在其他地方的代码中没有MapRoute或IgnoreRoute调用,而且我没有在任何位置编辑路由表。

如何更改此行为?

1 个答案:

答案 0 :(得分:0)

我怀疑您的应用程序根目录下有一个名为Configuration的物理文件夹。 ASP.NET MVC路由引擎优先选择路由上的物理文件夹。一种可能的方法是在路线定义之后将RouteExistingFiles属性设置为true

routes.MapRoute(
    "Default", 
    "Configuration", 
    new { controller = "DeviceConfiguration", action = "Index" 
});
routes.RouteExistingFiles = true;