C# – How to find a user’s Active Directory display name in a C# web application


I'm writing a web application which uses windows authentication and I can happily get the user's login name using something like:

 string login = User.Identity.Name.ToString();

But I don't need their login name I want their DisplayName. I've been banging my head for a couple hours now…

Can I access my organisation's AD via a web application?

Best Answer

How about this:

private static string GetFullName()
            DirectoryEntry de = new DirectoryEntry("WinNT://" + Environment.UserDomainName + "/" + Environment.UserName);
            return de.Properties["displayName"].Value.ToString();
        catch { return null; }