Many times we need to change the default controller in ASP.NET MVC. To change this
first we need to understand how the default route is configured. This setting is
available in RouteConfig file (under App_Start folder).
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
The above setting means that when we run the application , Home controller is called and it's Index
method is executed.
If we want to set a new default route for the application we simply have to change the above setting.
Let us say we want to start the application by loading Catalogue inside Inventory controller.
We just need to make changes in the settings as below
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Inventory", action = "Catalogue", id = UrlParameter.Optional }
);
After making the above changes , the application will load Catalogue at start time.
0 Comment(s)