Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 776
Zubair Rana Avatar asked Jul 24 '18 19:07

Zubair Rana


People also ask

How do I set the default route in .NET Core Web API?

Right click your web project -> Select Properties -> Select the Debug tab on the left -> Then edit the 'Launch Url' field to set your own default launch url.

How do I change the default page in asp net?

Select Admin Tools --> IIS Manager --> Select your website from the list. Click on Default Document on the right hand side and Click Add . Move the entry to the top of the list using the arrows. You are done.

How would you setup the default route using endpoints?

UseEndpoints(endpoints => { endpoints. MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); Inside the call to UseEndpoints() , we use the MapControllerRoute() method to create a route by giving the name default .

How do I change the start page in .NET Core?

For Asp.Net Core 2.2 right click on Project → Properties → Debug and next to Launch Browser checkbox set path to the startup page you want.


2 Answers

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?}");

        });
like image 89
csharpQ Avatar answered Sep 20 '22 12:09

csharpQ


I solve this by using this code in ConfigureServices function (Startup.cs)

services.AddMvc().AddRazorPagesOptions(options => {
     options.Conventions.AddAreaPageRoute("Identity", "/Account/Login", "/Account/Login");
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
like image 28
Vichet Sen Avatar answered Sep 18 '22 12:09

Vichet Sen