Try our conversational search powered by Generative AI!

change UserName using Membership in the System.Web.Security

Vote:
 

Hi!

I want to change the UserName but its read only. 

var memberShipProvider = Membership.Providers["SqlServerMembershipProvider"];

var user = memberShipProvider.GetUser(providerUserKey, false); //Returns my user 

user.UserName = "new@email.com"; //PROBLEM read only
user.Email= "new@email.com"; //WORKS but its not the username =)

memberShipProvider.UpdateUser(user);

how would you do it? The things i have tested

  1. Create a new user with the roles from the old one and then delete the old user. Problem here was to keep the password since the GetPassword of the Roles provider needs to be enabled in web.config and only works on hashed password (thats what we are using)
  2. Other things that i can try is to change it directly in the database but that feels like a big no no?
#217142
Feb 18, 2020 13:52
Vote:
 

It's not epi-related, but asp.net related and you can do just that (changing in database) https://stackoverflow.com/questions/1001491/is-it-possible-to-change-the-username-with-the-membership-api

We usually recommend against direct database access but when you really need it, and if you are very very careful, we can't stop you

#217144
Feb 18, 2020 13:56
Jim Rubinsson - Feb 18, 2020 13:58
Thanks for the reply Quan. I know its not epi related but since you dont recommend changing it in the database i wanted to know how everyone else solved this issue =)
Quan Mai - Feb 18, 2020 14:00
We do not recommend changing in epi tables as we don't disclose it and it might change without notice, but Membership tables have been there since forever and I don't think they will change any time soon, if at all.
Daniel Ovaska - Feb 19, 2020 9:23
Yup I had this issue once as well. As Quan says. There is no API for it so you'll have to use old school SQL for it. Should be avoided if possible but...
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.