How do I find a user's Active Directory display name in a C# web application?

active-directory, c#

Solution

How about this:

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

Problem

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?

Original source

Related problems