【发布时间】:2018-03-20 10:55:20
【问题描述】:
我需要对 Forest 的所有 DC 进行 LDAP 查询。我找到了类似的post,代码如下:
using (Forest currentForest = Forest.GetCurrentForest())
{
using (GlobalCatalog globalCatalog = currentForest.FindGlobalCatalog())
{
using (DirectorySearcher searcher = globalCatalog.GetDirectorySearcher())
{
searcher.Filter = "filter to verify existence of user account according to supplied sid";
SearchResult result = searcher.FindOne();
return (result != null);
}
}
}
以上代码适用于我的测试场景。这是跨域查询信息的正确方法吗?还有很多其他帖子,他们手动输入 GC 位置或搜索域列表。因此,有什么我应该注意的或者这段代码可能出错的地方吗?
【问题讨论】:
-
在您的情况下建议使用 GC。在多站点环境中,您需要遍历全局目录以确保用户存在。请注意,只有一部分用户属性存储在 GC 中。 ObjectSid 属性存在。
标签: c# windows server active-directory ldap