Try our conversational search powered by Generative AI!

Update or Change Username

Vote:
 

Hi,

We have arequirement where we want to be able to allow users to change their UserName. As episerver it does not allow username to be changed. 

  • The username property of Membership object is readonly. So I am not able to change that.
  • Also the Edit screen in episerver admin side for CustomerContact->User Account->Edit, "UserName" is readonly.

Does this mean we can never change UserName? We do need to change it though. Would really appreciate any input. Thanks!

#117283
Feb 16, 2015 20:30
Vote:
 

You cannot change a username once it has been created, that is a restriction within ASP.NET. But you can create a new user in ASP.NET and link it to the Customer in Commerce.

Something like:

// Create new user

var target= Membership.CreateUser(newUserName, newPassword, userEmailAddress);

if (RoleExists(AppRoles.EveryoneRole) &&!SecurityContext.Current.CheckUserInGlobalRole(target, AppRoles.EveryoneRole))

SecurityContext.Current.AssignUserToGlobalRole(target, AppRoles.EveryoneRole);

// Add user to registered role

if (RoleExists(AppRoles.RegisteredRole) && !SecurityContext.Current.CheckUserInGlobalRole(target, AppRoles.RegisteredRole))

SecurityContext.Current.AssignUserToGlobalRole(target, AppRoles.RegisteredRole);

// Get Customer

var customerContact = CustomerContext.Current.GetContactForUser(currentUser);

//assign new user to customer

customerContact.UserId = ToTypedString(target.ProviderUserKey);

//  save customer

customerContact.SaveChanges();

// delete 'old' account

Membership.DeleteUser(oldUsername);

#117287
Edited, Feb 17, 2015 9:39
Vote:
 

Hi, 

Seems like it was discussed earlier here :

http://world.episerver.com/Forum/Developer-forum/-EPiServer-75-CMS/Thread-Container/2014/7/Change-Username/

#117290
Feb 17, 2015 12:35
Vote:
 

Hi sapna,

I haven't worked with Commerce before, I tested this with EPiServer CMS 7.5 only.

I guess you only want to change the username, and keep the old email.

Usernames are stored in the Users table. UserName is not PK / FK / unique constraint, so you can safely change it there.

User access rights are stored in tblContentAccess table. You need to change the Name column (free text).

Just make sure that 'new username' is not already in use.

#117293
Feb 17, 2015 13:10
* 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.