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.
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;
lblUsername.Text = "Unknown User";