首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在PrincipalSearcher Query C#中阻止子容器对象

在PrincipalSearcher Query C#中阻止子容器对象
EN

Stack Overflow用户
提问于 2011-09-02 21:49:58
回答 1查看 1.4K关注 0票数 3

如何防止在查询特定OU (子OU)时使用子容器对象?

为了清楚起见,我不想在结果集中包含子OU(子容器)中的用户对象。

给出类似于another stackoverflow post上的代码,例如:

代码语言:javascript
复制
// create a principal object representation to describe
// what will be searched 
UserPrincipal user = new UserPrincipal(adPrincipalContext);

// define the properties of the search (this can use wildcards)
user.Enabled = false;
user.Name = "user*";

// create a principal searcher for running a search operation
PrincipalSearcher pS = new PrincipalSearcher();

// assign the query filter property for the principal object 
// you created
// you can also pass the user principal in the 
// PrincipalSearcher constructor
pS.QueryFilter = user;

// run the query
PrincipalSearchResult<Principal> results = pS.FindAll();

Console.WriteLine("Disabled accounts starting with a name of 'user':");
foreach (Principal result in results)
{
    Console.WriteLine("name: {0}", result.Name);
}

谢谢,

维克多

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-09-02 22:30:11

不幸的是,这个(和其他一些)特性在PrincipalSearcher类中是不可见的。

你需要“深入”到底层的DirectorySearcher来设置这样的选项(比如页面大小):

代码语言:javascript
复制
DirectorySearcher ds = pS.GetUnderlyingSearcher() as DirectorySearcher;

if(ds != null)
{
   ds.SearchScope = SearchScope.Base;  // or SearchScope.OneLevel - your pick
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7284406

复制
相关文章

相似问题

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