简体   繁体   English

我可以从PrincipalSearcher中获得1000条以上的记录吗?

[英]Can I get more than 1000 records from a PrincipalSearcher?

I am trying to get all users from Active Directory using code: 我正在尝试使用代码从Active Directory中获取所有用户:

PrincipalContext ad = new PrincipalContext(contextType, adserviceName, adContext, ContextOptions.SimpleBind, username, password);
UserPrincipal u = new UserPrincipal(ad) {Name = "*"};
PrincipalSearcher search = new PrincipalSearcher { QueryFilter = u };
foreach (var principal in search.FindAll()) 
{
    //do something 
}

But it returns only first 1000 rows. 但是它仅返回前1000行。 How I can retrieve All users and without using DirectorySearcher. 如何在不使用DirectorySearcher的情况下检索所有用户。 Thanks. 谢谢。

I don't think you will be able to do that without using DirectorySearcher . 我认为如果不使用DirectorySearcher ,您将无法做到这一点。

Code snippet - 代码段-

// set the PageSize on the underlying DirectorySearcher to get all entries
((DirectorySearcher)search.GetUnderlyingSearcher()).PageSize = 1000;

Also see If an OU contains 3000 users, how to use DirectorySearcher to find all of them? 另请参阅如果一个OU包含3000个用户,如何使用DirectorySearcher查找所有用户?

You need to get the underlying DirectorySearcher and set the PageSize property on it: 您需要获取基础的DirectorySearcher并在其上设置PageSize属性:

using (PrincipalContext ad = new PrincipalContext(contextType, adserviceName, adContext, ContextOptions.SimpleBind, username, password))
{ 
    UserPrincipal u = new UserPrincipal(ad) {Name = "*"};

    PrincipalSearcher search = new PrincipalSearcher { QueryFilter = u };

    // get the underlying "DirectorySearcher"
    DirectorySearcher ds = search.GetUnderlyingSearcher() as DirectorySearcher;

    if(ds != null)
    {
        // set the PageSize, enabling paged searches
       ds.PageSize = 500;
    }


    foreach (var principal in search.FindAll()) 
    {
        //do something 
    }
}

您可以:

((DirectorySearcher)myPrincipalSearcher.GetUnderlyingSearcher()).SizeLimit = 20;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以从 DirectorySearcher 中获取 1000 多条记录吗? - Can I get more than 1000 records from a DirectorySearcher? 如何获取超过1000个html控件值的HttpContext.Current.Request? - how can i get HttpContext.Current.Request of more than 1000 html controls value? 我可以使用LINQ从Quickbooks Online ServiceContext取回100多个记录吗? - Can I use LINQ to get more than 100 records back from a Quickbooks Online ServiceContext? 超过1000条记录的GridView问题 - GridView issue with more than 1000 records 从 Azure 表存储中获取 1000 多个数据集 - Get more than 1000 datasets from an Azure Table Storage 如何从 ActiveDirectory 获取 1000 多个结果? - How to get more than 1000 results from ActiveDirectory? 如何在C#中列出来自Google Drive API V3的1000多条记录 - How to list of more than 1000 records from Google Drive API V3 in C# 一次性在SQL Server 2008中插入1000条以上的记录 - Insert more than 1000 records in SQL Server 2008 in one go 无法将超过1000条记录传递给kendo gridview - Not able to pass more than 1000 records to kendo gridview 如何从UserPrincipal或PrincipalSearcher获取域名 - Howto get domainname from UserPrincipal or PrincipalSearcher
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM