防止 PrimarySearcher 查询 C# 中的子容器对象

发布于 2024-12-02 10:20:11 字数 1097 浏览 1 评论 0原文

如何防止在对具有子容器(子 OU)的特定 OU 的查询中出现子容器对象?

澄清一下,我不想将用户对象包含在结果集中的子 OU(子容器)中。

鉴于另一个上的代码stackoverflow 帖子 例如:

// 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);
}

谢谢,

Victor

How can I prevent subcontainer objects in queries to a specific OU with subcontainers (child OU)?

To clarify, I don't want to include user objects in children OUs (subcontainers) in the result set.

Given something like the code on another stackoverflow post for example:

// 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);
}

Thanks,

Victor

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简单 2024-12-09 10:20:11

不幸的是,这个(以及其他一些)功能在 PrincipalSearcher 类上不直接可见。

您需要“深入”底层 DirectorySearcher 来设置如下选项(例如页面大小):

DirectorySearcher ds = pS.GetUnderlyingSearcher() as DirectorySearcher;

if(ds != null)
{
   ds.SearchScope = SearchScope.Base;  // or SearchScope.OneLevel - your pick
}

Unfortunately, this (and a few other) features aren't visible directly on the PrincipalSearcher class.

You need to "reach down" to the underlying DirectorySearcher to set options like this (and e.g. the page size):

DirectorySearcher ds = pS.GetUnderlyingSearcher() as DirectorySearcher;

if(ds != null)
{
   ds.SearchScope = SearchScope.Base;  // or SearchScope.OneLevel - your pick
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文