Search code examples
asp.net-mvcasp.net-web-apiasp.net-identityasp.net-roles

Removing user from role and checking


I have two roles (freeUser , subscribedUser) and when i try to remove a user from role (subscribed user) using

 await UserManager.RemoveFromRoleAsync(subscription.UserId, RoleName.SubscribedUser);

it succesfully delete him from AspNetUserRoles table but when i check again to see if the user is subscribed using

     var roles = ((ClaimsIdentity)User.Identity).Claims
            .Where(c => c.Type == ClaimTypes.Role)
            .Select(c => c.Value);

        var enumerable = roles as IList<string> ?? roles.ToList();

or using User.IsInRole(RoleName.SubscribedUser)

it's return ture ! and the user is still in role subscribedUser even that i checked the AspNetUserRoles table and he is delete


Solution

  • Delete your cookies history, check in different browser or re-start the application. Sometimes, session will validate the user even nolonger exists in database.