ASP.NET路由 - 忽略路线与特定扩展名的文件,无论目录 [英] ASP.NET Routing - Ignore routes for files with specific extension, regardless of directory

查看:90
本文介绍了ASP.NET路由 - 忽略路线与特定扩展名的文件,无论目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我要删除的文件任何映射的路线具有一定的文件扩展名。

Say I want to remove any mapped routes for files with a certain file extension.

 RouteTable.Routes.Ignore("{root}.hello");

不过,只要我进入不应用'忽略'规则的任何工程的子文件夹为在根目录下的扩展名 .hello 的任何文件。

香港专业教育学院尝试了很多不同的组合,但似乎无法得到一个不会抛出一个编译器异常,或者无法正常工作?

Ive tried lots of different combinations, but can't seem to get one that doesn't throw a compiler exception, or not work?

推荐答案

查看<一个href=\"http://haacked.com/archive/2008/07/14/make-routing-ignore-requests-for-a-file-extension.aspx\">Phil's关于这个博客。基本上,你会做这样的事情:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆