在我的 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 中指定 LoginPath
和 LogoutPath
:
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/