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;
}
source
share