Ray
Ray

Reputation: 4929

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

What Is the proper syntax to put in the RouteConfig.RegisterRoutes method in an ASP.NET MVC application if I want the app to ignore all urls that start with the word "score" like

http://myserver/score*.*

?

In other words, any url that starts with the text "score" I want my app to ignore.

I tried:

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

I also tried several other combinations of this syntax but can't quite get it right.

Here is what I have so far in my RouteConfig. It's pretty much the standard stuff.

 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 }
        );
    }
}

Upvotes: 5

Views: 12132

Answers (1)

freshbm
freshbm

Reputation: 5632

You should place your score*.* as a regEx expression in IgnoreRoute:

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

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

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

So for score.js and score.txt route you will add regEx that filters that routes.

Upvotes: 4

Related Questions