本文介绍了使用PrincipalSearcher找到与"用户;或QUOT;参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
时有可能使用 System.DirectoryServices.AccountManagement.PrincipalSearcher
使用或(而不是和)搜索基于多个参数。
即
//这里使用和
//(&(objectCategory=person)(!UserAccountControl:1.2。 840.113556.1.4.803:= 2)(及(SAM帐户名=汤姆*)(显示名称=汤姆*)))
变种searchPrinciple =新UserPrincipal(上下文);
searchPrinciple.DisplayName =汤姆*;
searchPrinciple.SamAccountName =汤姆*;
变种搜索=新PrincipalSearcher();
searcher.QueryFilter = searchPrinciple;
VAR的结果= searcher.FindAll();
和我想使用类似这种(以LDAP)搜索 PrincipalSearcher
(不是的DirectorySearcher
)
// (!及(objectCategory属性=人)(的UserAccountControl:1.2.840.113556.1.4.803:= 2)(|(SAM帐户名=汤姆*)(显示名称=汤姆*)))
解决方案
这abviously不可能的,这里是一个workarround:
列表< UserPrincipal> searchPrinciples =新的List< UserPrincipal>();
searchPrinciples.Add(新UserPrincipal(上下文){显示名称=汤姆*});
searchPrinciples.Add(新UserPrincipal(上下文){SAM帐户=汤姆*});
searchPrinciples.Add(新UserPrincipal(上下文){中间名=汤姆*});
searchPrinciples.Add(新UserPrincipal(上下文){给定名称=汤姆*});
名单,LT;主>结果=新的List<主>();
变种搜索=新PrincipalSearcher();
的foreach(在searchPrinciples VAR项)
{
=搜索新PrincipalSearcher(项目);
results.AddRange(searcher.FindAll());
}
Is it possible to use System.DirectoryServices.AccountManagement.PrincipalSearcher
to search based on multiple parameters using "or" (not "and").
i.e.
// This uses an and
//(&(objectCategory=person)(!UserAccountControl:1.2.840.113556.1.4.803:=2)(&(SAMAccountName=tom*)(DisplayName=tom*)))
var searchPrinciple = new UserPrincipal(context);
searchPrinciple.DisplayName = "tom*";
searchPrinciple.SamAccountName = "tom*";
var searcher = new PrincipalSearcher();
searcher.QueryFilter = searchPrinciple;
var results = searcher.FindAll();
and I would like a search similar to this (in LDAP) using PrincipalSearcher
(not DirectorySearcher
)
// (&(objectCategory=person)(!UserAccountControl:1.2.840.113556.1.4.803:=2)(|(SAMAccountName=tom*)(DisplayName=tom*)))
解决方案
It's abviously not possible, here is a workarround:
List<UserPrincipal> searchPrinciples = new List<UserPrincipal>();
searchPrinciples.Add(new UserPrincipal(context) { DisplayName="tom*"});
searchPrinciples.Add(new UserPrincipal(context) { SamAccountName = "tom*" });
searchPrinciples.Add(new UserPrincipal(context) { MiddleName = "tom*" });
searchPrinciples.Add(new UserPrincipal(context) { GivenName = "tom*" });
List<Principal> results = new List<Principal>();
var searcher = new PrincipalSearcher();
foreach (var item in searchPrinciples)
{
searcher = new PrincipalSearcher(item);
results.AddRange(searcher.FindAll());
}
这篇关于使用PrincipalSearcher找到与"用户;或QUOT;参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!