I have been working on a website for some time now.
I am using the membership, role and profile providers which are working correctly.
I have a standard createuserwizard control where a user can register. When a user registers, I want to add him to a certain role like this:
Roles.AddUserToRole(Profile.UserName, "Member");
I do this through the userCreated event trigger.
There's also a adminpage where an admin should be able to change the role of a user, I did that like this:
DropdownList ddl = ((DropDownList)sender);
String usr = ddl.enter code here
if (Roles.IsUserInRole(usr, "Member")) {
Roles.RemoveUserFromRole(usr, "Member");
}
if (Roles.IsUserInRole(usr, "Visitor")) {
...
switch (ddl.selectedIndex)
case 0:
Roles.AddUserToRole(usr, "Admin");
case 1:
...
This doesn't work either. If I go to the database itself, the user wasn't added to the aspnet_UserInRoles.
Extra details:
When I create a user, he can see the adminpages, which is not intended. Security trimming is working correctly, when I add the user manually to the aspnet_UsersInRoles table I can't reach the memberpages anymore as intended.
The newly created user isn't added to any role, although he can see all pages he shouldn't be able to see. This is freaking me out!