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

10,146

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.

Share:
10,146
Ray
Author by

Ray

I'm a Montreal-based software developer with a strong background in Windows development, database development, and web development. I currently specialize in Microsoft's .NET, C#, and MVC technologies with a multitude of successful projects under my belt. After completing my university degree in Computer Science, I began as a computer consultant helping many businesses around Montreal reach their I.T. goals. Now after 20 years of experience, I enjoy developing with the latest web technologies, and constantly learning the newer ones as they come along.

Updated on June 04, 2022

Comments

  • Ray
    Ray almost 2 years

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