如何使用LdapConnection 类链接 Ldap服务器
来源:互联网 发布:js中修改class 编辑:程序博客网 时间:2024/06/05 08:24
如何使用LdapConnection 类链接 Ldap服务器
C#提供了 LdapConnection 类用于连接Microsoft Active Directory 域服务或 LDAP 服务器的 TCP/IP 或 UDP LDAP 连接。
LdapConnection 类
LdapConnection 类创建与 Microsoft Active Directory 或 LDAP 服务器的 TCP/IP 或 UDP LDAP 连接。
命名空间: System.DirectoryServices.Protocols
程序集: System.DirectoryServices.Protocols(在 system.directoryservices.protocols.dll 中)
C#
public class LdapConnection : DirectoryConnection, IDisposable
下面是连接 Ldap的连接方法和大家分享下: 1 static LdapConnectionldapConnection; 2 static string ldapServer; 3 static NetworkCreden
C#提供了 LdapConnection 类用于连接Microsoft Active Directory 域服务或 LDAP 服务器的 TCP/IP 或 UDP LDAP 连接。
下面是连接 Ldap的连接方法和大家分享下:
1static LdapConnection ldapConnection;
2 static string ldapServer;
3 static NetworkCredential credential;
4 static string targetOU;
5 static string pwd;
6 public void LdapBind()
7 {
8 ldapServer = "172.18.69.204:389";
9 targetOU = "cn=Manager,dc=tst,dc=com";
10 pwd = "000000";
11
12 //credential = new NetworkCredential(String.Empty, String.Empty);
13 credential = new NetworkCredential(targetOU, pwd);
14
15
16 string dn = "";
17
18 //ldapConnection = new LdapConnection(new LdapDirectoryIdentifier(ldapServer));
19 //ldapConnection.SessionOptions.ProtocolVersion = 3;//Ldap协议版本
20 //ldapConnection.AuthType = AuthType.Anonymous;//不传递密码进行连接
21
22 ldapConnection = new LdapConnection(ldapServer);
23 ldapConnection.AuthType = AuthType.Basic;
24 ldapConnection.Credential = credential;
25
26 try
27 {
28 Console.WriteLine("链接.");
29 ldapConnection.Bind();
30 Console.WriteLine("链接成功");