如何在asp.net mvc中手动重新生成当前的userClaims和角色

时间:2014-11-30 21:00:02

标签: c# asp.net-mvc claims-based-identity asp.net-identity-2

我使用asp.net身份作为我的安全框架,我知道regenerateIdentity中的app.UseCookieAuthentication

我正在向我的用户添加一些声明,例如fullname,可能通过个人资料页面更新的电子邮件,如何在更新用户个人资料时更新当前用户声明?

1 个答案:

答案 0 :(得分:2)

这是我用的, 使用以下方法再次使用此用户注销并重新登录

private async Task SignInAsync(User user, bool isPersistent)
{
   AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
   var identity = await user.GenerateUserIdentityAsync(UserManager);
   AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
}