域登录获得用户名称

DirectoryEntry entry = new DirectoryEntry();
       entry.Path = "LDAP://OU=People,DC=RCOMM,DC=local";
       entry.AuthenticationType = AuthenticationTypes.Secure;
       DirectorySearcher search = new DirectorySearcher(entry);
       search.Filter = "(SAMAccountName=liuda)";
       search.PropertiesToLoad.Add("DisplayName");

       SearchResultCollection results = search.FindAll();
       if (results != null && results.Count > 0)
       {
           Response.Write(results[0].Properties["DisplayName"][0].ToString());
       }
       else
       {
           Response.Write("Unknown User");
       }

原文地址:https://www.cnblogs.com/binaryworms/p/1692329.html