如何在ASP.NET MVC3中路由到/ Configuration / URL?(How do I route to /Configuration/ URL in ASP.NET MVC3?)

编程入门 行业动态 更新时间:2024-10-26 20:21:32
如何在ASP.NET MVC3中路由到/ Configuration / URL?(How do I route to /Configuration/ URL in ASP.NET MVC3?)

这适用于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调用,而且我没有在任何位置编辑路由表。

我该如何改变这种行为?

This is for an ASP.NET MVC3 web application. In RegisterRoutes I have the following as my only line:

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

When I run the project, going to the URL /Configuration/ gives me a 404 error. However if I change the word Configuration to any other word, such as:

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

Then going to the URL /Configuratio/ loads just fine. It seems as if ASP.NET is simply refusing to route to the URL /Configuration/.

Again, this is the only line in RegisterRoutes; I've tried commenting out everything else to debug this. I have no MapRoute or IgnoreRoute calls in my code anywhere else, and I am not editing the routing table in any location.

How can I change this behavior?

最满意答案

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

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

I suspect that you have a physical folder called Configuration under the root of your application. The ASP.NET MVC routing engine has preference for physical folders over routes. One possible way is to set the RouteExistingFiles property to true after your route definition:

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

更多推荐

Configuration,URL,MapRoute,NET,电脑培训,计算机培训,IT培训"/> <meta name=&quo

本文发布于:2023-07-17 13:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1145021.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   如何在   NET   ASP   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!