Warm tip: This article is reproduced from serverfault.com, please click

How to set login page as start page in mvc application?

发布于 2017-05-30 05:40:53

I am using mvc application. I want to add a login page for my mvc application. I created a login.cshtml file for login form (it contains user name and password). When I run the project, it starts with the home page. I want to start with login page. How can I achieve this?

Questioner
Nivitha G
Viewed
0
Zaheer Ul Hassan 2017-05-30 13:49:34

Go to App_Start folder in your solution and open RouteConfig.cs and replace this method with your code:

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional }
        );
    }

Hope it help you!