将Identity Serve 4与.Net Core 3.1 一起使用,剃刀页面。也使用 Cookie 身份验证
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
Run Code Online (Sandbox Code Playgroud)
问题 -
在 Web 应用程序中,John 登录了 2 次
因此,如果 John 在没有从以前的浏览器注销的情况下再次尝试在 Firefox 上第三次登录,那么我想强行从 Chrome 上的第一次登录中注销 John。
我可以跟踪会话表中的登录信息,包括会话 ID、用户 ID 等。但我不知道如何使用会话 ID 从特定会话中注销用户。
请帮忙。
谢谢
使用下面的代码通过自定义声明进行登录,并且工作正常。
private async Task SignInAsync(ApplicationUser user)
{
var claims = await _claimsPrincipalFactory.CreateAsync(user);
claims.Identities.First().AddClaims(new[]
{
new Claim("xxx", "111"),
new Claim("yyy", "222")
});
await HttpContext.SignInAsync(IdentityConstants.ApplicationScheme, claims);
}
Run Code Online (Sandbox Code Playgroud)
但是当尝试在服务中使用 HttpContext 进行访问时,如下所示
var claims = HttpContext.User.Identities.FirstOrDefault().Claims.ToList();
Run Code Online (Sandbox Code Playgroud)
它返回 0 项索赔。
请帮忙。
c# asp.net-identity asp.net-core identityserver4 asp.net-core-3.1