I have a RadioButtonList “chklRoles” which has 4 buttons. I want to update database aspnet_UserInRoles if I select a role. But it seems that the Aspnet Membership Provider doesn’t have an update method. How can I do it?
protected void chklRoles_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (string role in Roles.GetRolesForUser(userName))
{
if (chklRoles.Items.FindByText(role).Selected == true)
{
// update role;
// Roles.DeleteRole("origin_role");
// Roles.AddUserToRole(userName, role);
}
}
}
Edit: I think that to delete it and add it with a new role maybe an option. But please give me an advice.
update: each user only can have one role. What I want is how to switch roles by clicking the radio button. Update meants a new role will replace the older role.
You can use the RoleProvider to add or remove roles from a user. You’ll have to determine what roles are to be added and/or removed. That would look something like this:
Note that I haven’t had a chance to check this code thoroughly.