Reputation: 2351
I have a problem about getting user's firstname and surname (fullname) from Active Directory. The code is below.
No problem with runing the project on my local. I can take data whatever I want. After publishing the project to remote server, it don't allow me to get firstname and surname (fullname), it just allows to get domain name and username. How can I fix it?
private string GetNameSurname()
{
string[] retVal;
//Pull the username out of the domain\user string.
retVal = Page.User.Identity.Name.Split(new string[] { @"\"},StringSplitOptions.RemoveEmptyEntries);
DirectoryEntry userEntry = new DirectoryEntry("WinNT://" + retVal[0] + "/" + retVal[1]);
string namesurname = (string)userEntry.Properties["fullname"].Value;
//return retVal[1];
//retVal[1] gives username.
//retVal[0] gives domain name
return namesurname;
}
Upvotes: 0
Views: 3331
Reputation: 131
Are you running the code to test for the same user?
Are you testing against AD in dev, Windows local accounts have a Full Name field (optional) but in AD the fields are named differently. Also, are you talking to the same version of AD.
According to the MSDN article there is no field called Full Name, only First Name and Surname and Display Name.
Upvotes: 1
Reputation: 486
I think your problem is about credentials. Try to add an administrator username and password when conecting to active directory.
Upvotes: 0