httpcontext.signinasync((做什么?我称之为,但我的httpcontext中没有任何改变。当我从用cookie的用户那里收到新请求时,它仍然具有匿名用户。我不确定是否有失败或如何检查。
这就是我当前设置用户cookie并调用httpcontext.signinasync((
的方式 private async void AddUserCookie(AuthRequest authRequest)
{
var claims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, authRequest.UserName),
new Claim(ClaimTypes.Name, authRequest.UserName),
new Claim(ClaimTypes.Email, "TestClaim@Test.com")
};
var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
var authProperties = new AuthenticationProperties
{
AllowRefresh = true,
ExpiresUtc = DateTimeOffset.UtcNow.AddDays(1),
IsPersistent = true,
IssuedUtc = DateTimeOffset.UtcNow,
};
await this._httpContextAccessor.HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties).ConfigureAwait(false);
我想对幕后发生的事情进行一些澄清。我尝试查看源代码,但没有很多意义。
在stratup.configure检查
app.UseAuthentication();
app.UseAuthorization();