問題描述
我想忽略多個通配符路由.使用 asp.net mvc preview 4,它們附帶:
I'd like to ignore multiple wildcard routes. With asp.net mvc preview 4, they ship with:
RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
我還想添加以下內容:
RouteTable.Routes.IgnoreRoute("Content/{*pathInfo}");
但這似乎破壞了在我的程序中生成 url 的一些助手.想法?
but that seems to break some of the helpers that generate urls in my program. Thoughts?
推薦答案
這里有兩種可能的解決方案.
There are two possible solutions here.
為忽略路由添加一個約束,以確保只有應該被忽略的請求才會匹配該路由.有點笨拙,但應該可以.
Add a constraint to the ignore route to make sure that only requests that should be ignored would match that route. Kinda kludgy, but it should work.
RouteTable.Routes.IgnoreRoute("{folder}/{*pathInfo}", new {folder="content"});
您的內容目錄中有什么?默認情況下,Routing 不會路由磁盤上存在的文件(實際上是檢查 VirtualPathProvider).因此,如果您將靜態內容放在 Content 目錄中,則可能不需要忽略路由.
What is in your content directory? By default, Routing does not route files that exist on disk (actually checks the VirtualPathProvider). So if you are putting static content in the Content directory, you might not need the ignore route.
這篇關于Asp.Net Routing:如何忽略多個通配符路由?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!