开发者

How to delete all roles of a list of users using membership. -MVC

开发者 https://www.devze.com 2023-04-09 14:55 出处:网络
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

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);
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消