1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Changing User Name

Changing User Name

4 posts, 0 answered
  1. OakTree Digital
    OakTree Digital avatar
    27 posts
    Registered:
    06 Sep 2012
    15 Feb 2012
    Link to this post
    Is there any way to change a username once a user has been created? The thread here for SF 3.x says no:
    http://www.sitefinity.com/devnet/forums/sitefinity-3-x/security/change-username.aspx

    Should I presume this is also the case for 4.x?
  2. Victor Velev
    Victor Velev avatar
    1345 posts
    Registered:
    06 Jul 2015
    16 Feb 2012
    Link to this post
    Hi,

    You can use our API to change the username. Here is a code sample for you:

    public void ModifyUser(string username, string newUsername)
            {
                UserManager userManager = UserManager.GetManager();
                UserProfileManager profileManager = UserProfileManager.GetManager();
     
                User user = userManager.GetUsers().Where(u => u.UserName == username).SingleOrDefault();
     
                if (user != null)
                {
                    user.SetUserName(newUsername);
     
                    userManager.SaveChanges();
                }
            }


    Regards,
    Victor Velev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Markus
    Markus avatar
    2763 posts
    Registered:
    25 Nov 2005
    16 Feb 2012
    Link to this post
    Dear Victor
    The user name can not be changed in the back-end but with a few lines of code.
    Just wondering what would happen if you asing the name of an allready existing user?
    Markus
  4. Victor Velev
    Victor Velev avatar
    1345 posts
    Registered:
    06 Jul 2015
    16 Feb 2012
    Link to this post
    Hi Markus,

    You most probably will get an error that such username exists, but in order to avoid that you can create some custom logic for checking whether the desired username exists in the database.

    Greetings,
    Victor Velev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
4 posts, 0 answered