Sunday, April 10, 2016

Asp.Net MVC Set Startup Page

In Asp.Net Web Farms we set the startup page by just right clicking the page and selecting Set as Startup Page, however in Asp.Net MVC Applications we need to set this in the Global.asax.cs file. In this post we shall see on how to configure the default start up page for an Asp.Net MVC Application.
When an MVC application first starts, the Application_Start method is called. This method, in turn, calls the RegisterRoutes method. The RegisterRoutes method creates the route table. By Default a route with the name Default is created when you create the project, we can change the route map in this method to set the Start Up page for the Application.

1. Open you Asp.Net MVC Applications using Visual Studio 2008/2010
2. Open the Global.asax.cs file
3. In the
RegisterRoutes method, set the default Controller and Action as follows.

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Login", action = "Index", id = UrlParameter.Optional }           );
}

Here I have set
Login as the default controller and Index as the default method for the Application Startup.

4. Now build and run the application, the view corresponding to the default controller and action should get displayed in the Browser.


Search Flipkart Products:
Flipkart.com

2 comments:

akmal niazi khan said...

This blog awesome and i learn a lot about programming from here.The best thing about this blog is that you doing from beginning to experts level.

Love from

UI UX Design Training said...

Very interesting blog. A lot of blogs I see these days don't really provide anything that attract others, but I'm most definitely interested in this one. Just thought that I would post and let you know.