You will just need to remove the "Domain\" part from the REMOTE_USER to get the person's username by itself then use it to search ldap using the samaccountname and return the displayname. For example:
DirectoryEntry de = new DirectoryEntry("LDAP://...", ldapusername, password);
DirectorySearcher ds = new DirectorySearcher(de);
ds.PropertiesToLoad.Add("displayname");
ds.SearchScope = SearchScope.Subtree;
ds.Filter = "(sAMAccountName=" & username & ")";
SearchResult result = ds.FindOne();
If the user is found you can return the displayname with result.properties("displayname").value. I can probably post a complete function later.
gww
Contributor
2143 Points
458 Posts
Re: How can I retrieve the users full name using LDAP?
Dec 14, 2011 10:57 PM|LINK
You will just need to remove the "Domain\" part from the REMOTE_USER to get the person's username by itself then use it to search ldap using the samaccountname and return the displayname. For example:
DirectoryEntry de = new DirectoryEntry("LDAP://...", ldapusername, password); DirectorySearcher ds = new DirectorySearcher(de); ds.PropertiesToLoad.Add("displayname"); ds.SearchScope = SearchScope.Subtree; ds.Filter = "(sAMAccountName=" & username & ")"; SearchResult result = ds.FindOne();If the user is found you can return the displayname with result.properties("displayname").value. I can probably post a complete function later.