How to make Login page as a default route in ASP .NET Core 2.1?

Zubair Rana picture Zubair Rana · Jul 24, 2018 · Viewed 8.8k times · Source

I am beginner in ASP .NET Core 2.1 and working on project which is using ASP .NET Core 2.1 with individual authentication. I want to make my login page as my default route instead of Home/Index:

            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");

Any help how can i change it as ASP .NET Core 2.1 as Login is now used as a razor page instead of MVC Action View.

Answer

csharpQ picture csharpQ · Aug 31, 2018

Use this in ConfigureServices method.

services.AddMvc().AddRazorPagesOptions(options=> {
   options.Conventions.AddAreaPageRoute("Identity", "/Account/Login",""); 
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

then in Configure method

 app.UseMvc(routes =>
        {
            routes.MapRoute(
               name: "default",
               template: "{controller=Home}/{action=Index}/{id?}");

        });