Rename AccountController in ASP.NET Core

Viewed 149

In my ASP.NET Core MVC application, I would like to rename AccountController to something else ('Login', 'Authorization', does not matter the specific name).

But when I do this, the site still tries to route to /Account/Login even though there is no such thing. What do I need to do in order to stop this and have it use the right route?

I am setting options.LoginPath in services.ConfigureApplicationCookie but this does not seem to change things.

Here is my config setup:

services.ConfigureApplicationCookie(options =>
            {
                options.Cookie.Path = "/";
                options.AccessDeniedPath = new PathString($"/{nameof(Errors)}/{nameof(Errors.Access_Denied)}");
                options.ExpireTimeSpan= TimeSpan.FromMinutes(5);    // note: testing to see if this enforces logout based on minutes of idle time
                options.SlidingExpiration = true;
                options.LoginPath = new PathString($"/{nameof(Authorization.Authorization)}/{nameof(Authorization.Authorization.Login)}");
            }); 

Any suggestions? (Please ignore the nameof calls if they confuse you)

1 Answers

In a Core 3.1 project with custom auth, I specify LoginPath and LogoutPath like this in Startup#ConfigureServices:

        services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            })
            .AddCookie(options =>
            {
                options.Cookie.Name = ...
                options.Cookie.Path = "/";
                options.LoginPath = "/Login";
                options.LogoutPath = "/Logout";
                options.AccessDeniedPath = ...;
            });
Related