自定义身份验证方案授权失败-asp.net-core 3.0
我正在使用:自定义身份验证方案授权失败-asp.net-core 3.0,asp.net-core,asp.net-core-mvc,asp.net-identity,Asp.net Core,Asp.net Core Mvc,Asp.net Identity,我正在使用: services.AddAuthentication().AddCookie("custom", options=> { options.LoginPath = "/admin/in"; options.LogoutPath = "/admin/out"; }); 在ConfigureServices中注册自定义身份验证方案 当我尝试在控制器中使用此方案时: [Authorize(Rol
services.AddAuthentication().AddCookie("custom", options=> {
options.LoginPath = "/admin/in";
options.LogoutPath = "/admin/out";
});
在ConfigureServices
中注册自定义身份验证方案
当我尝试在控制器中使用此方案时:
[Authorize(Roles = "admin", AuthenticationSchemes = "custom")]
public ActionResult Index()
{
return View();
}
它只是将我重定向到登录页面,即使用户已登录且角色正确
现在,如果我将AuthenticationScheme
更改为:
[Authorize(Roles = "admin", AuthenticationSchemes = "Identity.Application")]
public ActionResult Index()
{
return View();
}
一切正常,用户得到授权
自定义身份验证方案的设置中是否缺少某些内容?我如何让我的自定义身份验证方案以与Identity.Application
相同的方式工作
谢谢
ps:我正在使用asp.net core 3.0 preview 9,似乎设置
options.ForwardAuthenticate=“Identity.Application”代码>解决此问题:
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication().AddCookie("custom", options=> {
options.LoginPath = "/admin/in";
options.LogoutPath = "/admin/out";
options.AccessDeniedPath= "/admin/in";
options.ForwardAuthenticate = "Identity.Application";
});
}
这真的应该被记录下来