Get User's first and last name
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?
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");That worked! I should have figured that out since I had the custom field part figured out. Thanks!