toneez
asked on
ASP.NET, C#, Active Directory - How do I display the fullname?
First off: I am using ASP.NET C# and Active Directory.
My question is... I have a login system that works off of active directory / windows auth. When the person logs in I currently have their login name showing (i.e. Welcome smithjo) I would like to show their full name (i.e. Welcome Joe Smith!). I have been looking all over and trying many examples of how to do this with no luck.
Can anyone help me out? Currently I am using this code, which is throwing the error: System.NullReferenceExcept ion: Object reference not set to an instance of an object.
Code:
My question is... I have a login system that works off of active directory / windows auth. When the person logs in I currently have their login name showing (i.e. Welcome smithjo) I would like to show their full name (i.e. Welcome Joe Smith!). I have been looking all over and trying many examples of how to do this with no luck.
Can anyone help me out? Currently I am using this code, which is throwing the error: System.NullReferenceExcept
Code:
string ldapPath = "LDAP://test.com/OU=staff,DC=test,DC=com";
DirectoryEntry currentUser = new DirectoryEntry(ldapPath);
if (currentUser != null)
{
string firstName = currentUser.Properties["givenName"].Value.ToString();
string lastName = currentUser.Properties["sn"].Value.ToString();
lblFirstName.Text = firstName;
lblLastName.Text = lastName;
}
else
{
lblUsername.Text = "Unknown User";
}
ASKER
I tried displayName as well already and it does not solve the issue unfortunately.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
currentUser.Properties["di