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

Forums / Developing with Sitefinity / Get User's first and last name

Get User's first and last name

3 posts, 1 answered
  1. Amanda Shafer
    Amanda Shafer avatar
    198 posts
    Registered:
    12 Oct 2012
    09 Aug 2011
    Link to this post
    I'm trying to retrieve the logged in user's first and last name.  I have the following:

    UserManager manager = UserManager.GetManager();
    User user = manager.GetUser(HttpContext.Current.User.Identity.Name);
    mUserName = user.Email + user.FirstName.ToString() + ' ' + user.LastName.ToString();

    However FirstName and LastName are coming up null. Is there a better way to do this?
                
  2. Anton Mernov
    Anton Mernov avatar
    110 posts
    Registered:
    03 Dec 2008
    09 Aug 2011
    Link to this post
    Hi Amanda,

    Actually, first name and last name are properties of user profile. To retrieve them you have to use the code something like this:

    UserManager userManager = UserManager.GetManager();
    User user = userManager.GetUser(HttpContext.Current.User.Identity.Name);
    UserProfileManager userProfileManager = UserProfileManager.GetManager();
    UserProfile profile = userProfileManager.GetUserProfile(user.Id, typeof(SitefinityProfile).FullName);
    var firstName = Telerik.Sitefinity.Model.DataExtensions.GetValue(profile, "FirstName");
    var lastName = Telerik.Sitefinity.Model.DataExtensions.GetValue(profile, "LastName");

    Have a look at this post for more information.

    I hope this helps,
    Anton
    Answered
  3. Amanda Shafer
    Amanda Shafer avatar
    198 posts
    Registered:
    12 Oct 2012
    09 Aug 2011
    Link to this post
    That worked! I should have figured that out since I had the custom field part figured out. Thanks!
3 posts, 1 answered