How to ignore a specific route in ASP.NET MVC routing

What is the correct syntax for applying the RouteConfig.RegisterRoutes method in an ASP.NET MVC application if I want the application to ignore all the URLs starting with the word โ€œratingโ€, for example

http://myserver/score*.*

?

In other words, any URL starting with the text โ€œratingโ€ I want my application to be ignored.

I tried:

 routes.IgnoreRoute("score*.*/{*pathInfo}"); 

I also tried several other combinations of this syntax, but can't figure it out correctly.

Here is what I have so far found in my RouteConfig. This is pretty much standard material.

  public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Order", action = "Add", id = UrlParameter.Optional } ); } } 
+5
source share
1 answer

You must put your score *. * as regEx expression in IgnoreRoute:

 routes.IgnoreRoute("{score}/{*pathInfo}", new { score = @"score*.*" }); 

For more general answers, you can use this pattern to ignore the routes you want:

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

So, for route score.js and score.txt, you add regEx, which filters the routes.

+4
source

All Articles