There is no direct way to change the role name in a membership provider.
I would get a list of users who are in the role that you want to rename, then remove from the list, delete the role, create a role with a new name, and then add the users that were discovered earlier to the role using the new name.
public void RenameRoleAndUsers(string OldRoleName, string NewRoleName) { string[] users = Roles.GetUsersInRole(OldRoleName); Roles.CreateRole(NewRoleName); Roles.AddUsersToRole(users, NewRoleName); Roles.RemoveUsersFromRole(users, OldRoleName); Roles.DeleteRole(OldRoleName); }
This will change the role name for all users in the role.
Follow-up: the roles used to ensure that the user plays only his role in the system, in this way User.IsInRole (ROLE_NAME) will help you enforce BR securities for the user and the role he is in. If you can change the role names on the fly, how are you going to verify that the user is really in this role. Itβs good that I understood when I asked about this.
rtpHarry edit: Converted pseudocode example to compiled C # method
CheGueVerra
source share