Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Asp.net MVC路由与某些文件扩展名不匹配_C#_Asp.net Mvc_Routing - Fatal编程技术网

C# Asp.net MVC路由与某些文件扩展名不匹配

C# Asp.net MVC路由与某些文件扩展名不匹配,c#,asp.net-mvc,routing,C#,Asp.net Mvc,Routing,当路由中包含某些文件扩展名时,我遇到路由不匹配的问题。我怀疑这可能是一个IIS问题,但我似乎无法找到它 首先,我关闭了RouteExistingFiles: routes.RouteExistingFiles = false; 然后我有以下路线: routes.MapRoute("", "category/{category}.aspx", new { controller = "Category", action = "View" }); 并且以下url与此路由不匹配: http://my

当路由中包含某些文件扩展名时,我遇到路由不匹配的问题。我怀疑这可能是一个IIS问题,但我似乎无法找到它

首先,我关闭了RouteExistingFiles:

routes.RouteExistingFiles = false;
然后我有以下路线:

routes.MapRoute("", "category/{category}.aspx", new { controller = "Category", action = "View" });
并且以下url与此路由不匹配:

http://mysite/category/test.aspx
routes.MapRoute("sitemap", "sitemap.xml", new { controller = "Resource", action = "Sitemap" });
但是,如果我删除文件扩展名并将路由保存到:

routes.MapRoute("", "category/{category}", new { controller = "Category", action = "View" });
然后,上面的url与{category}设置为“test.aspx”匹配

我对这条路线也有同样的问题:

http://mysite/category/test.aspx
routes.MapRoute("sitemap", "sitemap.xml", new { controller = "Resource", action = "Sitemap" });
奇怪的是,我没有在所有带有文件扩展名的路由上遇到这个问题。以下路线似乎对我很有效:

routes.MapRoute("", "favicon.ico", new { controller = "Resource", action = "Favicon" });
routes.MapRoute("", "min.css", new { controller = "Resource", action = "Css" });
routes.MapRoute("", "min.js", new { controller = "Resource", action = "JavaScript" });
routes.MapRoute("", "rsd.xml", new { controller = "MetaWeblog", action = "Rsd" });

对于.aspx和.xml扩展名,有什么我应该注意的吗?这可能是IIS问题吗?有没有比使用更好的调试方法?

如果url包含.xml或.aspx,您的问题是请求没有被定向到这些操作

那我想这应该是真的

routes.RouteExistingFiles = true;
更新:

我在两个场景中测试了运行在IIS7中的站点的以下路由

routes.MapRoute("sitemap", "{sitemap}.xml", 
                   new { controller = "Resource", action = "Sitemap" });
使用
RouteExistingFiles时
为false

在这种情况下,如果存在sitemap.xml文件,则请求将定向到该文件,否则请求将定向到操作

如果
RouteExistingFiles
为true


当sitemap.xml文件存在或不存在时,请求总是被定向到操作。

我刚刚遇到了这个问题。对我来说,没有为没有托管处理程序的文件调用路由。以下配置适用于我:

<system.webServer>
  <modules>
    <remove name="UrlRoutingModule-4.0" />
    <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
  </modules>
</system.webServer>


URL中匹配的文件在磁盘上不存在,因此它们不符合现有文件的条件。我希望这些路径路由到控制器操作,而不是提供静态文件。您创建的aspx路由在我的盒子中工作,应用程序在IIS 7I中运行。我有一个类似的问题,不知道您是否找到了解决方法?