【发布时间】:2018-02-26 15:58:52
【问题描述】:
我正在使用以下代码在 ASP.NET Core 2.0 中使用 cookie 进行身份验证
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
cookies 设置如下:
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)
});
我做了一些研究,但没有找到解决方案。这是我用过的a link to the doc:
谁能告诉我如何解决这个问题?
【问题讨论】:
标签: c# authentication asp.net-core