How to search Global Catalog (whole forest) using PrincipalContext(如何使用 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);
}
}
我有类似于上面的代码,它使用 PrincipalContext 类在 Active Directory 中搜索用户信息.
I have code similar to the above that searches Active Directory for user information using PrincipalContext class.
如您所见,我在搜索过程中传入了域名.我如何修改这种代码的和平来代替搜索整个森林(即全局目录)但仍然使用 PrincipalContext 类?
As you can see i pass in the domainName during the search. How can i modify this peace of code to instead search the entire forest (i.e Global Catalog) but still use the PrincipalContext class?
我似乎找不到使用 PrincipalContext 类进行全局目录搜索的工作示例.
I can't seem to find a working example that uses PrincipalContext class to do a Global Catalog search.
我看过这篇文章 如何在具有多棵树的 AD 林中的全局目录中搜索用户 但海报似乎表明他们没有找到使用 PrincipalContext 类的解决方案,他们不得不切换回 DirectorySearcher.
I have seen this post How to search for users in Global Catalog within AD forest with multiple trees but the poster seems to suggest that they did not find a solution that uses PrincipalContext class, they had to switch back to DirectorySearcher.
是否有任何 PrincipalContext 类代码示例演示在整个林中搜索(全局目录)?
Is there any PrincipalContext class code sample that demonstrates searching in the whole forest (Global Catalog)?
推荐答案
好的,我搞定了.我只需要像下面那样更改我的代码.
ok, i got it working. I just had to change my code like below.
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);
}
}
这篇关于如何使用 PrincipalContext 搜索全局目录(整个森林)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 PrincipalContext 搜索全局目录(整个森林
基础教程推荐
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
