0

我使用 Active Directory。我编写了一个方法,如何使用过滤器从 Active Directory 中获取所有用户,并在ArrayList我的DropDownList.

编码:

 private ArrayList GetReceiverList(string Domain) 
        {
            ArrayList List = new ArrayList();

            DirectoryEntry Entry = new DirectoryEntry(Domain);

            string filter = "(&(objectClass=user)(objectCategory=user)(!userAccountControl:1.2.840.113556.1.4.803:=2)(sn=*)(|(telephoneNumber=*)(mail=*))(cn=*))"; 

            DirectorySearcher Searcher = new DirectorySearcher(Entry, filter);

            foreach (SearchResult usr in Searcher.FindAll())
            {
                List.Add(GetLdapProperty(usr, "displayName"));
            }

            return List;
        }

这项工作,我现在想使用System.DirectoryServices.AccountManagement,为此我编写了一个方法,这也有效。但我想在我的第一个方法中使用过滤器。我怎么能做到这一点?

我的新方法的代码:

 public static ArrayList GetAllActiveDirectoryUsersByDisplayName(string dc)
        {
            ArrayList list = new ArrayList();

            PrincipalContext ctx = new PrincipalContext(ContextType.Domain, dc);
            UserPrincipal u = new UserPrincipal(ctx);
            u.Surname = "*";
            PrincipalSearcher ps = new PrincipalSearcher(u);
            PrincipalSearchResult<Principal> results = ps.FindAll();

            foreach (UserPrincipal usr in results)
            {
                list.Add(usr.Name);
            }

            list.Sort();

            return list;
        }

更新:

我想在我的新方法中使用这个过滤器:

 string filter = "(&(objectClass=user)(objectCategory=user)(!userAccountControl:1.2.840.113556.1.4.803:=2)(sn=*)(|(telephoneNumber=*)(mail=*))(cn=*))"; 
4

0 回答 0