【发布时间】:2013-08-30 15:30:30
【问题描述】:
我试图在我的组织 Active Directory 中搜索用户。
如果 FirstName or LastName or DisplayName 匹配特定的字符串值,它应该返回用户。
我的代码:
// create your domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
UserPrincipal qbeUser = new UserPrincipal(ctx);
qbeUser.GivenName = "Ramesh*";
// qbeUser.Surname = "Ramesh*";
// qbeUser.DisplayName= "Ramesh*";
PrincipalSearcher srch = new PrincipalSearcher(qbeUser);
// find all matches
foreach(var found in srch.FindAll())
{
//
}
问题是我只能通过一个过滤器进行搜索。
我可以 AND 过滤器,但不能 OR。是否有可用的解决方案?
【问题讨论】:
-
参见a possible solution for this issue here - 使用
UserPrincipal的可扩展性来访问anr属性(不明确的名称解析),该属性允许在多个与名称相关的属性中进行搜索 -
@marc_s:感谢您的解决方案。它工作正常。您可以将其发布为答案。这样我才能接受?
标签: c# active-directory userprincipal principalcontext principalsearcher