【发布时间】:2015-01-29 12:26:26
【问题描述】:
我尝试从 Active Directory 中的对象获取所有属性的列表。
我现在拥有的是这样的:
List<User> users = new List<User>();
try
{
DirectoryEntry root = new DirectoryEntry("LDAP://RootDSE");
root = new DirectoryEntry("LDAP://" + root.Properties["defaultNamingContext"][0]);
DirectorySearcher search = new DirectorySearcher(root);
search.Filter = "(&(objectClass=user)(objectCategory=person))";
search.PropertiesToLoad.Add("samaccountname");
search.PropertiesToLoad.Add("displayname");
search.PropertiesToLoad.Add("mail");
search.PropertiesToLoad.Add("telephoneNumber");
search.PropertiesToLoad.Add("department");
search.PropertiesToLoad.Add("title");
SearchResultCollection results = search.FindAll();
if (results != null)
{
foreach (SearchResult result in results)
{
foreach (DictionaryEntry property in result.Properties)
{
Debug.Write(property.Key + ": ");
foreach (var val in (property.Value as ResultPropertyValueCollection)) {
Debug.Write(val +"; ");
}
Debug.WriteLine("");
}
}
}
}
catch (Exception ex)
{
}
但它只获取我使用 PropertiesToLoad 添加的属性。是否可以动态获取所有属性?
【问题讨论】:
-
如果你在这里查看drawed chapins的答案:stackoverflow.com/questions/23176284/…你就会知道为什么要通过propertiestoLoad来限制。 VeryFast vs VerySlow 你打电话..
标签: c# active-directory