【发布时间】:2015-03-20 16:43:33
【问题描述】:
我遇到了一个问题,如果我尝试扩展 UserPrincipal 类 PrincipalContextSearcher > 使用扩展类作为查询过滤器时,不会返回正确的结果。
例如,如果我创建以下 UserPrincipal 的最小扩展
[DirectoryRdnPrefix("CN")]
[DirectoryObjectClass("user")]
public class UserPrincipalExtended : UserPrincipal
{
public UserPrincipalExtended(PrincipalContext context) : base(context) { }
public UserPrincipalExtended(PrincipalContext context, string samAccountName, string password, bool enabled) : base(context, samAccountName, password, enabled) { }
}
如果我使用(非扩展)UserPrincipal 进行搜索,如下所示:
using (var searchCritera = new UserPrincipal(context))
{
searchCritera.SamAccountName = searchTerm;
using (var searcher = new PrincipalSearcher(searchCritera))
{
foreach (var principal in searcher.FindAll())
{
... do stuff
}
}
}
它将正确地只返回用户帐户。但是,如果我使用 UserPrincipalExtended 而不是 UserPrincipal,它会返回与计算机的匹配项以及其他各种我不想要的行为。我想要做的就是能够添加一些额外的属性以在 UserPrincipal 中检索,但在添加任何内容之前简单地扩展类似乎会改变过滤行为。
我缺少什么以及如何使用扩展的 UserPrincipal 获取 PrincipalSearcher ?
【问题讨论】:
标签: c# active-directory