Skip to main content
 首页 » 编程设计

c#之获取所有用户的快速方法+指定属性+使用来自 LDAP 的分页

2024年02月20日9qq号

我想从事件目录中获取所有用户及其属性 我检查了很多主题,包括 Linq to LDAP + enter link description here

但一切似乎都很复杂。

我从这个开始:

public SearchResultCollection GetAllUsrs() 
     { 
         var dirEntry = new DirectoryEntry(string.Format("LDAP://{0}/{1}", "x.y.com", "DC=x,DC=y,DC=com")); 
         var searcher = new DirectorySearcher(dirEntry) 
         searcher.Filter = "(&(&(objectClass=user)(objectClass=person)))"; 
         searcher.PageSize = 999; 
 
         return searcher.FindAll(); 
 
     } 

我如何使用分页,因为事件目录当时只会返回 1000 条记录 + 如何指定属性?

问题: 我想使用控制台应用程序查询最多包含 60 K 用户的域 我要指定属性 性能非常重要。 你能指导我实现这一目标的最佳方法吗?

请您参考如下方法:

不需要分页。 AD 将返回超过 1000 个对象。将 PageSize 保留为 0 并根据需要设置 SizeLimit。如果您不确定,请使用 int.MaxValue ;)。