The function (RemoveFromRole in UserManager) to remove user from role is seriously buggy! If users has many roles the function seems to remove a random role but fortunately correct user.
Has anyone else experienced this?
The function (RemoveFromRole in UserManager) to remove user from role is seriously buggy! If users has many roles the function seems to remove a random role but fortunately correct user.
Has anyone else experienced this?
There is a bug tracking this issue http://aspnetidentity.codeplex.com/workitem/2069 As a workaround you can remove all roles for the user and add the ones for now. It is not the best solution but it will work
I experienced the exact same bug and it has been fixed in the 2.0.1. you only have to update.
I have encountered the bug with the method RemoveFromRoles. The error happend if i try to remove a role in which the user isn't. I had to write a method to get the names of the roles the user is in. That way i could only remove the user from those roles.
public List<string> GetRoleNamesOf(IdentityUser user)
{
var roles = user.Roles;
List<string> roleNames = new List<string>();
foreach (var role in roles)
{
var roleName = this.FindById(role.RoleId).Name;
roleNames.Add(roleName);
}
return roleNames;
}