Question

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!

Était-ce utile?

La solution

Alright, I fixed the issue that it wouldn't assign the role after registering. You'd think that userCreated is called after the user has been logged in, but it isn't. Profile.UserName results in an empty string!

I'm still having problems with the adminpage though... I get the username value from the tooltip of the dropdownlist. By hovering over the ddl I can visually verify that the username is indeed in the tooltip attribute.

Assuming that the same problem exists here -> the usr (username) string is empty. Why can't I get the value?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top