gpt4 book ai didi

asp.net - ASP.NET Core 2 中不同区域的身份验证和 LoginPath

转载 作者:行者123 更新时间:2023-12-02 10:17:40 25 4
gpt4 key购买 nike

ASP.NET Core 2

帮我配置AddAuthentication两个路线:用户(用户帐户)和管理区域。

例如,如果用户未登录并尝试输入 /Account/Orders/他将被重定向到/Account/SignIn/ .

但是如果有人尝试访问/Admin/Orders/必须重定向到 /Admin/Signin/

尚未找到解决方案 ATM。

最佳答案

解决了!

admin区域( Controller )我们使用Authorize attr。 arg.: [Authorize(AuthenticationSchemes = "backend")] 就是这样。

顺便说一句,我们可以通过访问 AddCookie 的选项和事件中的 HttpContext 进行任何调整。

配置:

services
.AddAuthentication(o =>
{
o.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, o =>
{
o.LoginPath = new PathString("/account/login/");
})
.AddCookie("backend", o =>
{
o.LoginPath = new PathString("/admin/account/login/");
});

关于asp.net - ASP.NET Core 2 中不同区域的身份验证和 LoginPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45926389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com