Search code examples
c#asp.net-mvcclaims-based-identityasp.net-identity-2

How can I regenerate current userClaims and roles manually in asp.net mvc


I'm using asp.net identity as my security framework, and I'm aware of regenerateIdentity in my app.UseCookieAuthentication.

I'm adding some claims to my user e.g. fullname, email that might be updated through profile page, how can I update current user claims when updating user profile?


Solution

  • Here is what i used, signout and signin again with this user using below method

    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);
    }