问题描述
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 搜索全局目录(整个森林)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)