加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – Active Directory:PropertiesToLoad获取所有属性

发布时间:2020-12-15 04:26:47 所属栏目:百科 来源:网络整理
导读:我尝试从Active Directory中的对象获取所有属性的列表. 我现在拥有的是: ListUser users = new ListUser();try{ DirectoryEntry root = new DirectoryEntry("LDAP://RootDSE"); root = new DirectoryEntry("LDAP://" + root.Properties["defaultNamingConte
我尝试从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添加的属性.是否可以动态获取所有属性?

解决方法

如果未在PropertiesToLoad中指定任何内容,则应获取所有属性.只需使用search.PropertiesToLoad.Add删除这些行.

但是,获取域中所有用户的所有属性可能非常繁重.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读