Search code examples
asp.netmembershiproles

Membership user is not found after UserName was changed


Help please if you know how.

I'm using Membership but allow to change UserName of specified user. I had user named Customer bound to role Customer, and then his username was changed to 123. Then i try to do something to get Roles of this user and get an error or empty result.

Roles.RemoveUserFromRoles(UserName, Roles.GetAllRoles()); // get exception - user 123 does not exist
String[] userRoles = Roles.GetRolesForUser(UserName); // returns String[]{0}

Then i went to IIS manager panel and saw that selected role still has renamed user but renamed user was not added to any role. DB table UserInRoles (which set the link between User and Role) has relevant record and all UserIDs and RoleIDs are correct.

So i do not understand if all links in DB connected within IDs, why after i changed UserName this link was broken?

I will appreciate any help, advices and information.

Thanks, Art


Solution

  • Well, Membership sucks - this is the answer i will never use it anymore in any project. This is the answer.

    Workaround for question above is to create your own methods to edit user by ID.