Using MapRoute for Registering Routes in ASP.NET MVC 4

The previous article explained How to Create and Register a Route in ASP.NET MVC using the Route class and add it to the RouteCollection.

This article will explain how to use MapRoute class for registering routes in ASP.NET MVC 4.

Using MapRoute for Registering Routes in ASP.NET MVC 4

The MapRoute is defined in the RouteCollection and can be used without creating the instance of the MvcRouteHandler.

Below is a sample code snippet of the RouteConfig class demonstrating the usage of the MapRoute method.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

using System.Web.Routing;

namespace MvcApplication1

{

public class RouteConfig

{

public static void RegisterRoutes(RouteCollection routes)

{

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

routes.MapRoute("NewRoute", "Abundantcode/{controller}/{action}");

}

}

}
%d bloggers like this: