c# - 在 ASP.NET Core 中重命名 AccountController

标签 c# asp.net-mvc asp.net-core

在我的 ASP.NET Core MVC 应用程序中,我想将 AccountController 重命名为其他名称(“登录”、“授权”,具体名称无关紧要)。

但是当我这样做时,该网站仍然尝试路由到 /Account/Login 即使没有这样的东西。我需要做什么才能阻止这种情况并让它使用正确的路线?

我正在services.ConfigureApplicationCookie中设置options.LoginPath,但这似乎并没有改变事情。

这是我的配置设置:

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

有什么建议吗? (如果调用名称让您感到困惑,请忽略它们)

最佳答案

在具有自定义身份验证的 Core 3.1 项目中,我在 Startup#ConfigureServices 中指定 LoginPathLogoutPath:

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

关于c# - 在 ASP.NET Core 中重命名 AccountController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65617424/

相关文章:

c# - 如何查找(强类型)集合中包含的类型?

javascript - typescript 泛型?

javascript - MVC 中的 Kendo UI 网格页面大小

asp.net-mvc - 我必须在哪一层编码

c# - Web API未接收序列化对象的json

c# - 测试 Controller Get() 方法的最佳方法

asp.net - 在 asp.net vnext 上使用不记名 token 身份验证刷新 token

c# - SQL Server 原子增量

c# - 停止自定义 ASP.NET Core 配置提供程序中的 SqlDependency

c# - 具有C#或同等功能的Arduino音频频谱