我正在尝试查询 AD 以检索用户数据。
查询工作正常,但是在枚举通过 GetDirectoryEntry 返回的属性时我无法看到我在 Active Directory 资源管理器中看到的所有属性。
下面的代码片段:
offEntry = pResult.GetDirectoryEntry();
foreach (PropertyValueCollection o in offEntry.Properties)
{
Debug.Print(o.PropertyName + " = " + o.Value.ToString());
}
我看到了“displayName”和“SAMAccountName”等属性,但不是我真正想要的属性,例如:“postalCode”、“streetAddress”。
我曾尝试为这个特定问题寻找解决方案,但已走到尽头。我错过了什么???
问候彼得
您应该能够使用这样的搜索器类。
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(sAMAccountName=" + userAccount + ")";
search.PropertiesToLoad.Add("mail");
SearchResult result = search.FindOne();
然后通过行加载你想要的属性
search.PropertiesToLoad.Add("mail");
然后在您的 SearchResult
中您将能够读取属性
我是一名优秀的程序员,十分优秀!