C# 如何使用PrincipalContext搜索全局目录(整个林)
我有类似于上面的代码,它使用PrincipalContext类在Active Directory中搜索用户信息 如您所见,我在搜索过程中传入了域名。 如何修改这段代码来代替搜索整个林(即全局目录),但仍然使用PrincipalContext类 我似乎找不到一个使用PrincipalContext类进行全局目录搜索的工作示例 我看过这篇文章,但海报似乎暗示他们没有找到使用PrincipalContext类的解决方案,他们不得不切换回DirectorySearcherC# 如何使用PrincipalContext搜索全局目录(整个林),c#,active-directory,directoryservices,directoryentry,account-management,C#,Active Directory,Directoryservices,Directoryentry,Account Management,我有类似于上面的代码,它使用PrincipalContext类在Active Directory中搜索用户信息 如您所见,我在搜索过程中传入了域名。 如何修改这段代码来代替搜索整个林(即全局目录),但仍然使用PrincipalContext类 我似乎找不到一个使用PrincipalContext类进行全局目录搜索的工作示例 我看过这篇文章,但海报似乎暗示他们没有找到使用PrincipalContext类的解决方案,他们不得不切换回DirectorySearcher 是否有任何PrincipalC
是否有任何PrincipalContext类代码示例演示在整个林(全局目录)中进行搜索?好的,我已经让它工作了。我只需要像下面这样更改代码
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);
}
}
myUserList AppUsers = new myUserList();
using (PrincipalContext pcxt = new PrincipalContext(ContextType.Domain, "my-global-catalogue-server.subdomain.domain.com:port", "DC=subdomain,DC=domain,DC=com"))
{
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);
}
}