Say I want to remove any mapped routes for files with a certain file extension.
RouteTable.Routes.Ignore("{root}.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?
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()));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With