SaaS CMS has officially launched! Learn more now.

change UserName using Membership in the System.Web.Security



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 = ""; //PROBLEM read only
user.Email= ""; //WORKS but its not the username =)


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?
Feb 18, 2020 13:52

It's not epi-related, but related and you can do just that (changing in database)

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

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.