How to set Default Controller in asp.net MVC 4 & MVC 5

Adrian10 BEN picture Adrian10 BEN · Jan 20, 2013 · Viewed 165.9k times · Source

How do I set Default Controller for my ASP.NET MVC 4 project without making it HomeController?

How should I setup a default Area when the application starts?

Answer

Dave Alperovich picture Dave Alperovich · Jan 20, 2013

the best way is to change your route. The default route (defined in your App_Start) sets /Home/Index

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

as the default landing page. You can change that to be any route you wish.

routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters*
        new { controller = "Sales", action = "ProjectionReport", 
        id = UrlParameter.Optional }
);