【发布时间】:2016-07-14 12:08:58
【问题描述】:
myUserList AppUsers = new myUserList();
using (PrincipalContext pcxt = new PrincipalContext(ContextType.Domain, domainName))
{
UserPrincipal User = new UserPrincipal(pcxt);
User.EmailAddress = emailString;
PrincipalSearcher srch = new PrincipalSearcher(User);
foreach (var principal in srch.FindAll())
{
var p = (UserPrincipal)principal;
myUserRow User = AppUsers.NewUsersRow();
User.FirstName = p.GivenName;
User.LastName = p.Surname;
User.Email = p.EmailAddress;
AppUsers.AddUsersRow(User);
}
}
我有与上面类似的代码,它使用 PrincipalContext 类在 Active Directory 中搜索用户信息。
如您所见,我在搜索过程中传入了域名。 我怎样才能修改这种和平的代码来代替搜索整个森林(即全局目录)但仍然使用 PrincipalContext 类?
我似乎找不到使用 PrincipalContext 类进行全局目录搜索的工作示例。
我看过这篇帖子How to search for users in Global Catalog within AD forest with multiple trees,但发帖人似乎暗示他们没有找到使用 PrincipalContext 类的解决方案,他们不得不切换回 DirectorySearcher。
是否有任何 PrincipalContext 类代码示例演示了在整个森林中的搜索(全局目录)?
【问题讨论】:
标签: c# active-directory directoryservices directoryentry account-management