当包含特定文件扩展名的路由时,我遇到了路由不匹配的问题。我怀疑它可能是一个IIS问题,但我似乎无法追踪它。
首先,我关闭了RouteExistingFiles:
routes.RouteExistingFiles = false;
然后我有以下路线:
routes.MapRoute("", "category/{category}.aspx", new { controller = "Category", action = "View" });
并且以下网址与此路线不匹配:
http://mysite/category/test.aspx
但是,如果我删除文件扩展名并将路由封装到:
routes.MapRoute("", "category/{category}", new { controller = "Category", action = "View" });
然后上面的url匹配{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问题吗?有没有比使用RouteDebugger更好的方法进行调试?
答案 0 :(得分:1)
如果网址包含.xml或.aspx,您的问题是请求是否未定向到这些操作?
然后我想这应该是真的,
routes.RouteExistingFiles = true;
<强>更新强>
我在两种情况下测试了IIS7中运行的站点的以下路由。
routes.MapRoute("sitemap", "{sitemap}.xml",
new { controller = "Resource", action = "Sitemap" });
RouteExistingFiles
为false,
在这种情况下,当sitemap.xml文件存在时,请求将被定向到该文件,否则请求将被定向到该操作。
RouteExistingFiles
为真,
当sitemap.xml文件存在或不存在时,请求始终指向该操作。
答案 1 :(得分:0)
我刚遇到这个问题。对我来说,没有为没有托管处理程序的文件调用路由。以下配置对我有用:
<system.webServer>
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
</system.webServer>