【问题标题】:Search Users in Active Directory based on First Name, Last Name and Display Name根据名字、姓氏和显示名在 Active Directory 中搜索用户
【发布时间】: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


【解决方案1】:

See a possible solution for this issue in this other SO question.

您需要使用UserPrincipal 的可扩展性来创建后代类,以便访问anr 属性(anr = 模糊名称解析),该属性允许同时搜索多个与名称相关的属性。

【讨论】:

【解决方案2】:

看看 DirectorySearcher。 This article 可能会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-12
    • 2011-08-19
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 2012-02-19
    相关资源
    最近更新 更多