I have a list of username's in a string array . l wanna give the all selected users a new role .I can easily give that using membership But before doing that i want remove all roles assigned to selected users. How can 开发者_如何学Goi do that ..
or at least how can i remove all roles assigned to a particular user?
Roles.RemoveUserFromRoles(user.UserName, Roles.GetRolesForUser(user.UserName));
Try this for one user
Roles.RemoveUserFromRoles
or
Roles.RemoveUsersFromRoles
for many.
Here is a good tutorial about Roles, http://www.asp.net/security/tutorials/assigning-roles-to-users-cs
I know its old...but I was just looking for this myself:
MembershipUser mUser = Membership.GetUser((Guid)User.UserID);
foreach (var role in Roles.GetAllRoles())
{
Roles.RemoveUserFromRole(mUser.UserName, role);
}
精彩评论