13.10. Custom Routing

By now, you should have a basic understanding of URL routing in MVC and how important it is. Routing is very flexible, and the default can be modified by changing the rules in Global.asax. Right-click Global.asax (it handles global events within your application), and select View Code. Your code will look similar to the following:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "Default",                                              // Route name
        "{controller}/{action}/{id}",                           // URL with parameters
        new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
    );

}

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

But what's this code doing? I will ...

Get Introducing .NET 4.0: with Visual Studio 2010 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.