Get User's first and last name

Posted by Community Admin on 04-Aug-2018 19:59

Get User's first and last name

All Replies

Posted by Community Admin on 09-Aug-2011 00:00

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?
            

Posted by Community Admin on 09-Aug-2011 00:00

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

Posted by Community Admin on 09-Aug-2011 00:00

That worked! I should have figured that out since I had the custom field part figured out. Thanks!

This thread is closed