首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我能从PrincipalSearcher中得到1000多张唱片吗?

我能从PrincipalSearcher中得到1000多张唱片吗?
EN

Stack Overflow用户
提问于 2015-11-20 10:50:04
回答 3查看 2.2K关注 0票数 2

我试图让Active Directory中的所有用户使用代码:

代码语言:javascript
复制
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 
}

但是它只返回前1000行。如何在不使用DirectorySearcher的情况下检索所有用户。谢谢。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-11-20 11:24:29

我认为如果不使用DirectorySearcher.,你就无法做到这一点。

代码片段-

代码语言:javascript
复制
// set the PageSize on the underlying DirectorySearcher to get all entries
((DirectorySearcher)search.GetUnderlyingSearcher()).PageSize = 1000;

还请参见If an OU contains 3000 users, how to use DirectorySearcher to find all of them?

票数 2
EN

Stack Overflow用户

发布于 2015-11-20 11:30:57

您需要获取基础DirectorySearcher并在其上设置PageSize属性:

代码语言:javascript
复制
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 
    }
}
票数 1
EN

Stack Overflow用户

发布于 2019-01-07 16:38:17

您可以:

代码语言:javascript
复制
((DirectorySearcher)myPrincipalSearcher.GetUnderlyingSearcher()).SizeLimit = 20;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33824785

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档