Effective pagination with Active Directory searches

前端 未结 4 1229
广开言路
广开言路 2021-02-05 06:00

What would be an effective way to do pagination with Active Directory searches in .NET? There are many ways to search in AD but so far I couldn\'t find how to do it effectively.

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-05 06:23

        private static DirectoryEntry forestlocal = new DirectoryEntry(LocalGCUri, LocalGCUsername, LocalGCPassword);
        private DirectorySearcher localSearcher = new DirectorySearcher(forestlocal);
    
         public List GetAllUsers() 
        {
            List users = new List();
    
            localSearcher.SizeLimit = 10000;
            localSearcher.PageSize = 250;
    
            string localFilter = string.Format(@"(&(objectClass=user)(objectCategory=person)(!(objectClass=contact))(msRTCSIP-PrimaryUserAddress=*))");
    
            localSearcher.Filter = localFilter;
    
            SearchResultCollection localForestResult;
    
            try
            {
                localForestResult = localSearcher.FindAll();
    
                if (resourceForestResult != null) 
                {
    
                    foreach (SearchResult result in localForestResult) 
                    {
                        if (result.Properties.Contains("mail"))
                            users.Add((string)result.Properties["mail"][0]);
                    }
    
                }
    
            }
            catch (Exception ex) 
            {
    
            }
    
            return users;
        }
    

提交回复
热议问题