ASP.NET 路由 - 忽略具有特定扩展名的文件的路由,无论目录如何 [英] ASP.NET Routing - Ignore routes for files with specific extension, regardless of directory
问题描述
假设我想删除具有特定文件扩展名的文件的所有映射路由.
Say I want to remove any mapped routes for files with a certain file extension.
RouteTable.Routes.Ignore("{root}.hello");
适用于根目录中具有扩展名 .hello
的任何文件,但是一旦我进入任何子文件夹,忽略"规则就不会应用.
Works for any file that has the extension .hello
in the root directory, however as soon as i go into any subfolders the 'ignore' rule isn't applied.
我尝试了很多不同的组合,但似乎无法找到一种不会引发编译器异常或不起作用的组合?
Ive tried lots of different combinations, but can't seem to get one that doesn't throw a compiler exception, or not work?
推荐答案
查看 Phil 的博客 关于这个.基本上,你会做这样的事情:
Check out Phil's blog regarding this. Basically, you would do something like this:
示例 1:不对所有 .aspx 文件的任何请求执行路由:
Example 1: Do not perform routing for any request for all .aspx files:
routes.IgnoreRoute("{*allaspx}", new {allaspx=@".*.aspx(/.*)?"});
示例 2:不对 favicon.ico 的任何请求执行路由
Example 2: Do not perform routing for any request for favicon.ico
routes.IgnoreRoute("{*favicon}", new {favicon=@"(.*/)?favicon.ico(/.*)?"});
这篇关于ASP.NET 路由 - 忽略具有特定扩展名的文件的路由,无论目录如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!