ASP.NET Routing - Ignore routes for files with specific extension, regardless of directory

本小妞迷上赌 提交于 2019-11-29 03:48:15

Check out Phil's blog regarding this. Basically, you would do something like this:

Example 1: Do not perform routing for any request for all .aspx files:

routes.IgnoreRoute("{*allaspx}", new {allaspx=@".*\.aspx(/.*)?"});

Example 2: Do not perform routing for any request for favicon.ico

routes.IgnoreRoute("{*favicon}", new {favicon=@"(.*/)?favicon.ico(/.*)?"});

If you're using ASP.NET MVC, use IgnoreRoutes (MVC Extension method)

Routes.IgnoreRoute("{*foo*}", new { foo = @"someregextoignorewhatyouwant"});

If you're using ASP.NET Web Forms, use StopRoutingHandler which implements IRouteHandler.

routes.Add(new Route("*someregextoignorewhatyouwant*", new StopRoutingHandler()));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!