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

11,282

Solution 1

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!

Solution 2

Answering because I had the same question. My code looked like this in the startup.cs

app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");

        });

I changed the name of the controller and index to the controller and index i wanted it to call to.

app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Login}/{action=Register}/{id?}");

        });
Share:
11,282

Related videos on Youtube

Nivitha G
Author by

Nivitha G

Updated on July 04, 2022

Comments

  • Nivitha G
    Nivitha G almost 2 years

    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?

  • Zaheer Ul Hassan
    Zaheer Ul Hassan almost 7 years
    @NivithaG try this solution
  • Nivitha G
    Nivitha G almost 7 years
    Thanks. It is useful for me.