实例2 简介 所有LDAP用户的阅读清单 比6.0到VB。NET框架已经很容易进入像LDAP的网络解决方案。我看到很多人问LDAP使用。NET访问。在这篇文章中,我将试图解释如何检索所有LDAP用户列表。邮编:公共功能GetAllUsers如Hashtable(字符串ldapServerName#) "若要检索所有LDAP用户列表 "这个函数返回的HashTable _ldapServerName = ldapServerName DIM sServerName的String = quot; mailquot; DIM oRoot作为的DirectoryEntry =新的DirectoryEntry("LDAP:/ /"放大器,ldapServerName放大器; - "/ OU =,DC = mydomainname,DC = comquot;) DIM oSearcher DirectorySearcher =新DirectorySearcher(oRoot) DIM oResults作为SearchResultCollection 由于SearchResult中的DIM oResult DIM RetArray作为新的Hashtable() 尝试 oSearcher.PropertiesToLoad.Add("; uidquot";) oSearcher.PropertiesToLoad.Add("; givennamequot";) oSearcher.PropertiesToLoad.Add("; cnquot";)&# 160; oResults = oSearcher.FindAll 中的每个oResults oResult 如果不oResult.GetDirectoryEntry()属性"("cnquot)。值="",然后 RetArray.Add(oResult.GetDirectoryEntry()属性("uidquot;)值,_ oResult.GetDirectoryEntry()属性("; cnquot";)。) 结束如果 下一页 抓住作为例外五 "MSGBOX("错误是quot;放大器; e.Message) 返回RetArray END TRY 返回RetArray 端功能详细说明: 作为一个基本的,当我们正在编写与LDAP相关的应用,我们需要参考到System.DirectoryServices命名空间。要添加引用,只需右键单击该项目并选择"添加引用"。这将目前的接口选择。NET组件可以在所指的项目。在这份名单中,选择System.DirectoryServices.dll,并单击"添加"。现在,在项目,开放的形式,并在顶部添加以下行:进口System.DirectoryServices中 执行此操作后,System.DirectoryServices中是在应用程序进行访问。LDAP实现: 通常情况下,所有的元素和LDAP的对象存储在一个树结构。要访问此树结构,我们需要有一个根元素,使用,我们可以遍历所有的子元素。获取一个LDAP的根元素:作为DIM oRoot的DirectoryEntry =新的DirectoryEntry(quot; LDAP:/ / quot;放大器; _ ldapServerName放大器;"/ ou = People的,DC = mydomainname,DC = comquot;) 使用这条线,我们可以获取LDAP树结构的根。 现在,接下来的工作就是从LDAP树中找到用户的所有条目。本次搜索行动。NET框架提供了一个类,即DirectorySearcher.Dim oSearcher DirectorySearcher =新DirectorySearcher(oRoot) 这个类期望的DirectoryEntry的参数,并返回SearchResultCollection的数据。 要访问SearchResultCollection,我们需要使用SearchResult中的对象。搜索结果将包含我们在负载属性指定的字段。要指定要加载的属性,我们需要传递的字段的名称作为一个字符串来搜索对象的PropertiesToLoad方法。 例如 ![]() 确保您指定正确的字段名称。 现在,对象的搜索者的FindAll方法将返回SearchResults集合。这个集合将包含SearchResult中(上述规定),将与目录条目载入属性。 在这个例子中我已经把所有的关键和共性名称的唯一ID(UID),(CN)值作为价值在Hashtable。 |
|( 京ICP备09078825号 )
GMT+8, 2025-2-17 15:29 , Processed in 0.128300 second(s), 42 queries .