c# Active Directory 服务 findAll() 仅返回 1000 个条目

时间:2023-02-19
本文介绍了c# Active Directory 服务 findAll() 仅返回 1000 个条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
我可以得到超过 1000来自 Asp.Net 中 DirectorySearcher 的记录?

我正在使用 ADS 目录搜索器 findAll() 方法搜索现有登录名(如下面的代码所示).看起来 findall 方法只返回 1000 个条目,尽管条目多于此.我如何找到每次登录的所有()?

I am searching for existing logins using ADS Directory searcher findAll() method (as in following code). It appears the findall method returns only 1000 entries although there are more entries than that. How do I findAll() of every login ?

    IList<string> adslist = new List<string>();
    using (DirectoryEntry de = new DirectoryEntry("LDAP://armlink.com", null, null, AuthenticationTypes.Secure))
    using (DirectorySearcher ds = new DirectorySearcher(de, "(objectclass=user)", new string[] { "samaccountname" }))

        foreach (SearchResult sr in ds.FindAll())
        {
            string[] e = sr.Path.Split(new string[] { "LDAP://", "OU=", ",", "DC=", ".com", "/CN=" }, StringSplitOptions.RemoveEmptyEntries);
            ResultPropertyCollection pc = sr.Properties;
            adslist.Add(e[0] + "/" + pc["samaccountname"][0].ToString());
            //   Debug.WriteLine(adslist.Last());
        }

推荐答案

这是由于服务器端限制造成的.来自 DirectorySearcher.SizeLimit 文档:

This is due to a server-side limit. From the DirectorySearcher.SizeLimit documentation:

对象的最大数量服务器在搜索中返回.这默认值为零,这意味着使用服务器确定的默认大小限制为 1000 个条目.

The maximum number of objects that the server returns in a search. The default value is zero, which means to use the server-determined default size limit of 1000 entries.

还有:

如果您将 SizeLimit 设置为大于服务器确定的默认值 1000条目,使用服务器确定的默认值.

If you set SizeLimit to a value that is larger than the server-determined default of 1000 entries, the server-determined default is used.

基本上,除非有一种方法可以更改服务器端默认值,否则您将被限制为 1000 个条目.指定 PageSize 可能会让您一次获取某个数字,total 大于 1000 ......不确定.

Basically from this, it looks like unless there's a way of changing the server-side default, you're going to be limited to 1000 entries. It's possible that specifying a PageSize will let you fetch a certain number at a time, with a total greater than 1000... not sure.

顺便说一句,您似乎还应该在 SearchResultCollection 周围有一个 using 指令:

By the way, it looks like you should also have a using directive around the SearchResultCollection:

using (SearchResultCollection results = ds.FindAll())
{
    foreach (SearchResult sr in results) 
    {
        ...
    }
}

这篇关于c# Active Directory 服务 findAll() 仅返回 1000 个条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:“从服务器返回了一个推荐"从 C# 访问 AD 时的 下一篇:如何在 C# 中获取当前用户的 Active Directory 详细信

相关文章

最新文章