【问题标题】:How to get more than 1000 results from ActiveDirectory?如何从 ActiveDirectory 获得超过 1000 个结果?
【发布时间】:2018-05-22 17:41:10
【问题描述】:

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

【问题讨论】:

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


【解决方案1】:

我找到了以下解决方案

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

首先。获取包含用户的所有文件夹的列表。如果在任何文件夹中也有超过 1000 个文件夹,那么对于该文件夹,需要将文件夹列表获取到以下级别(LdapConnection.SCOPE_ONE)。

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

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

【讨论】:

    【解决方案2】:

    一次不能返回超过 1000 个。你需要组织循环。使用 LdapControl 类 (Novell.Directory.Ldap.NETStandard.dll)。这是作者的 Metacube 存储库,其中包含该项目的一个很好的工作示例。

    https://github.com/metacube/PagedResultsControl

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多