1、从LDAP服务器上面获取用户名

 
sAMAccountName是个人的CN结点中的一个属性,例如个人的CN的sAMAccountName的值为:Amy。我命名它为shortname,即短名

        public static void GetUser()
        {
            const string ldapPath = "LDAP://ibm.com/DC=ibm,DC=com";  //LDAP服务器地址
            DirectoryEntry entry = new DirectoryEntry(ldapPath);
            DirectorySearcher mySearcher = new DirectorySearcher(entry);
            //查询用户缩略名称为Amy的用户
            mySearcher.Filter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=Amy))"; ;  //过滤条件
            foreach (SearchResult resEnt in mySearcher.FindAll())
            {
                Console.WriteLine(resEnt.GetDirectoryEntry().Name.ToString());
            } 
        }

 

http://blog.sina.com.cn/s/blog_604364630100iya5.html

http://laintoday.iteye.com/blog/1664346

 

posted on 2015-08-05 18:54  AmyAlisa  阅读(451)  评论(0编辑  收藏  举报