You must Sign In to post a response.
  • Category: ASP.Net MVC

    Use of ignore route in MVC

    Hello All,

    I am new to MVC , someone please explain in detail the use of the below line in the method "RegisterRoutes" in Routing.

    I know the basics like this line ignores anything that ends with an axd. Still why do we need this ??? any specific reason on this.

    Line:routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  • #769508
    Hi Geetha,

    The line routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    will prevent users to access .axd files which are present in the solution.
    Internally HttpHandler will handle that request so what if again user enters the file name in the browser with .axd extensions? so to prevent user doing that we need to specify that IgnoreRoute.
    Not only that .axd you can even stop any extensions from user to avoid accessing,, you can even prevent one of the controller methods like below


    namespace IngoreRoute
    {
    public class RouteConfig
    {
    public static void RegisterRoutes(RouteCollection routes)
    {
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.IgnoreRoute("Product/"); //preventing product action method
    routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new
    {
    controller = "Home", action = "Index", id = UrlParameter.Optional
    }
    );
    }
    }
    }

    Sridhar Thota.
    Editor: DNS Forum.


  • Sign In to post your comments