Home > DeveloperSection > Interviews > How route table is created in ASP.NET MVC4?

Posted on    December-07-2012 8:38 AM

 ASP.NET MVC ASP.NET MVC 
Ratings:
 2 Answer(s)
  9520  View(s)
Rate this:

Vijay Shukla

Total Post:81

Points:405
Posted on    December-07-2012 1:00 AM

When an MVC4 application starts, the Application_Start() method is called. This method is calls the RegisterRoutes() method. Which is  creates the route table.


Abhishek Singh

Total Post:2

Points:10
Posted on    January-17-2014 1:00 AM

you need to register Routes in the Application_Start() method like this

protected void Application_Start()
{
RouteConfig.RegisterRoutes(RouteTable.Routes);
}

After that you need to override the method of RouteConfig Class like this
 public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            //routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute(
               name: "Blog",
               url: "Blog/{id}/{Title}",
               defaults: new { controller = "Blog", action = "Index", id = UrlParameter.Optional });

            //
            routes.MapRoute(
            name: "DeveloperSection",
            url: "DeveloperSection.aspx/{id}",
            defaults: new { controller = "Developer", action = "Index", id = UrlParameter.Optional });


            routes.MapRoute(
               name: "Articles",
                url: "Articless/{article_id}",
                //url: "{controller}/{article_id}",
               defaults: new { controller = "Articles", action = "Index", article_id = UrlParameter.Optional });
            // used for blog URL

            //
            routes.MapRoute(
               name: "Default",
               url: "{controller}/{action}",
               defaults: new { controller = "Home", action = "Index" });

            
            

        }


From this you need URL Routing in MVC 4

Don't want to miss updates? Please click the below button!

Follow MindStick