如何从ActiveDirectory获得超过1000个结果?

时间:2018-05-22 17:41:10

标签: c# active-directory .net-core

我遇到了一个问题。 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);
    }
}

1 个答案:

答案 0 :(得分:0)

我找到了以下解决方案

所有用户都在文件夹中。在每个文件夹中,用户不超过1000个。该文件夹与用户是同一个对象,但与另一个objectType。

首先。获取用户的所有文件夹列表。如果在任何文件夹中也有超过1000个文件夹,则对于此文件夹,必须将文件夹列表提供到以下级别(LdapConnection.SCOPE_ONE)。

第二个。找到找到的每个文件夹并收集其中的所有用户。

使用这种方法,每次迭代的搜索结果数量不会超过1000.如果仍然存在这种情况,那么在一个文件夹中有超过1000个用户,那么你就有问题。

相关问题