Search code examples
c#asp.netasp.net-mvc-5identity

How to change C# Identity Login page default route


I created a new project using Microsoft.Aspnet.Identity.samples for my authentication system.

As you know Visual Studio adds AccountController automatically to the project.

I just edited the Login action route using [Route("login")] attribute.

I added another Controller to my project called Dashboard with an Index method. Then I added an [Authorize] attribute to my dashboard controller.

When I call the URL https://localhost/Dashboard/Index and my request is not authenticated, the project authomaticaly redirects to https://localhost/Account/Login?ReturnUrl=%2Fdashboard and as I said I changed the Login route then my project gives me an error.

How can I change the default login URL?


Solution

  • At the file Startup.Auth.cs is a method called ConfigureAuth you can change the login path default to your custom route.