Error UserManager RemoveFromRole

The function (RemoveFromRole in UserManager) to remove a user from a role is a serious mistake! If users have many roles, the function seems to remove the random role, but, fortunately, the correct user.

Has anyone else experienced this?

+4
source share
3 answers

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 them at the moment. This is not the best solution, but it will work

+2
source

I experienced the same error and it was fixed in version 2.0.1. you only need to update.

+1

I encountered an error using the RemoveFromRoles method . The error occurs if I try to remove a role in which the user is not working. I had to write a method to get the names of the roles the user is in. Thus, I could only remove the user from these 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;
}
0
source

Source: https://habr.com/ru/post/1532783/


All Articles