我使用验证下面的代码在ASP.NET 2.0的核心使用cookie没有authenticationScheme指定,也没有发现DefaultChallengeScheme饼干认证
services
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie("MyCookieMiddlewareInstance", options =>
{
options.AccessDeniedPath = new PathString("/Account/Login");
options.LoginPath = new PathString("/Account/Login");
options.LogoutPath = new PathString("/Account/LogOff");
});
我得到一个错误“没有authenticationScheme是。指定,也没有发现DefaultChallengeScheme”
的饼干设置如下:
var claims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, userId.ToString()),
new Claim(ClaimTypes.Name, userName)
};
var identity = new ClaimsIdentity(claims, "Forms");
identity.AddClaim(new Claim(ClaimTypes.Role, "ADMIN"));
var principal = new ClaimsPrincipal(identity);
HttpContext.Authentication.SignInAsync("MyCookieMiddlewareInstance", principal, new AuthenticationProperties
{
IsPersistent = isPersistent,
ExpiresUtc = DateTime.UtcNow.AddYears(1)
});
我做了一些研究,但没有找到解决方案。这里是我使用的链接:https://docs.microsoft.com/en-us/aspnet/core/security/authentication/cookie?tabs=aspnetcore2x
任何人都可以请让我知道我该如何解决这个问题?
可能重复[ASP.NET Core 2.0身份验证中间件](https://stackoverflow.com/questions/ 45805411/asp-net-core-2-0-authentication-middleware) –