是否可以在用户登录后更新声明?我的站点中有前端和管理面板,基本上我使用 claims
来实现此目的。如果用户在前端以 Susan
身份登录,我会在我的代码中执行以下操作:
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
userIdentity.AddClaim(new Claim("Id", this.UserName));
... //other claims here
所以当用户最终登录到管理面板时(当仍然在前端登录时),我只想添加更多声明,例如:
userIdentity.AddClaim(new Claim("BackEndId", this.UserName));
如何实现?
最佳答案
为了能够读取 cookie 上的声明,您需要在同一请求期间为我们的用户签名并再次让他们重新登录:
idenityt.AddClaim(new Claim("myClaimType", "myClaimValue"));
var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
authenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, idenityt);
关于c# - 用户登录后更新声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31107276/