Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
163 views
in Technique[技术] by (71.8m points)

c# - Rename AccountController in ASP.NET Core

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)

question from:https://stackoverflow.com/questions/65617424/rename-accountcontroller-in-asp-net-core

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 = ...;
            });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...