Wednesday, March 12, 2014

Change default start page of ASP.NET MVC 4 application

Familiarizing myself with ASP.NET MVC 4 made me think, how can I change the default start page of using global.asax? The globax.asax only has declarations that calls methods and lacking the methods as seen in MVC 2-3 versions. Luckily, the structure of the project has been changed since the Routes have been transfered to App_Start folder. Below is the sample code to change the default start page using the the class RouteConfig.
Code:
public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
                defaults: new { controller = "Movies", action = "Index", id = UrlParameter.Optional }
            );
        }
Reference: App_start and global.asax in ASP.NET MVC 4

0 comments:

Post a Comment