[英]How to get more than 1000 results from ActiveDirectory?
我遇到了一個問題。 Linux 不支持 NetCor App System.DirectoryServices 的標准包。 決定轉移到 Novell.Directory.Ldap.NETStandard。
在 AD 中,有 1000 個搜索結果的限制。 如何使用 Novell.Directory.Ldap.NETStandard 在客戶端上返回 1000 多個結果?
這是我的代碼。 它只返回 1000 條記錄。
LdapSearchQueue queue = connection.Search("<this my base entry>",
LdapConnection.SCOPE_SUB,
"<this my filter>",
attr,
false,
(LdapSearchQueue)null,
new LdapSearchConstraints { MaxResults = 0 });
LdapMessage message;
while ((message = queue.getResponse()) != null)
{
if (message is LdapSearchResult)
{
LdapEntry entry = ((LdapSearchResult)message).Entry;
LdapAttributeSet attributeSet = entry.getAttributeSet();
var atr = attributeSet.getAttribute("sAMAccountName");
list.Add(atr.StringValue);
}
}
我發現以下解決方案
所有用戶都在文件夾中。 每個文件夾中的用戶數不超過1000。 該文件夾與用戶是同一對象,但具有另一個objectType。
第一。 獲取用戶的所有文件夾的列表。 如果在任何文件夾中也有超過1000個文件夾,則對於此文件夾,必須將文件夾列表獲取到以下級別(LdapConnection.SCOPE_ONE)。
第二。 轉到找到的每個文件夾並收集其中的所有用戶。
使用這種方法,每次迭代的搜索結果數不會超過1000。如果仍然存在這種情況,即在一個文件夾中有1000個以上的用戶,那么您就有了問題。
一次不能退回超過 1000 件。 你需要組織循環。 使用 LdapControl 類 (Novell.Directory.Ldap.NETStandard.dll)。 這是作者的 Metacube 存儲庫,其中包含一個很好的項目工作示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.