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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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 {<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="adccc1c1ccdeddd590ed">[email protected]</a>".*.aspx(/.*)?"});
Example 2: Do not perform routing for any request for favicon.ico
routes.IgnoreRoute("{*favicon}", new {<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3e585f48575d5150037e">[email protected]</a>"(.*/)?favicon.ico(/.*)?"});
Method 2
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()));
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0