Question

I have two roles in my web-application. Now I want to change the roles of some users. Can any one tell me How to change the User Roles using SQL

Was it helpful?

Solution

I suppose you use defalt RoleProvider and table for user roles was created by aspnet_regsql.exe. So all you need is - find specified user in table Memberships - find specified user role in table Roles - add a record to table UsersInRoles with specified membership id and specified role id

OTHER TIPS

In the System.Web.Security there is a Role class that has a AddUsersToRole method.

Example to use:

Roles.AddUserToRole("userName", "roleName");

and there is the same to remove:

Roles.RemoveUserFromRole("userName", "roleName");

or using sql as you asked: When you run the aspnet_regsql you get bunch of stored procedures. Such a stored procedure is the one named aspnet_UsersInRolesInsert. It is for adding users to roles.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top