我使用的是:
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预览版9
发布于 2019-09-11 02:02:47
设置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";
});
}这真的应该被记录下来
https://stackoverflow.com/questions/57866897
复制相似问题