域登录获得用户名称

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");
       }

posted on 2010-03-23 10:56  冰危节奏  阅读(339)  评论(0编辑  收藏  举报

导航