Change the Start Page in MVC application

When programmer runs the MVC application, it shows the default page having the address http://localhost:port/. Here localhost is the computer which is running that application at that time, means the client machine and the port is the number assigned for that application.

Run the application of simply press F5 and look out the default page as shown below:

Change the Start Page in MVC application

Now look out the default code written in the Route.Config file under the App_Start folder, which have some other files also. This code have information about the routes user write in the address bar of the browser.

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

This MapRoute method have three parameters listed above i.e. the name of route, format of url (route may have) and the last one will be the default page to be redirected if any route is not found. The last parameter itself have three values, controller decides the name of controller from which the action is to be called. Action decides about the action to be called from the controller.

And the last one is id, which decide about the id of the record if given in the route. It is an optional parameter for the route. Now change the action from Index to About and run the application, It seems the change the default page shown below:

Change the Start Page in MVC application

Comments

Popular posts from this blog

difference between structure and union in C Language

Difference between Linear search and Binary Search in c language

Difference between static and dynamic websites