我使用驗證下面的代碼在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) –