如何使用LdapConnection 类(1)链接 Ldap服务器

2025-03-22 16:17:05
推荐回答(1个)
回答1:

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"; 1112 //credential = new NetworkCredential(String.Empty, String.Empty);13 credential = new NetworkCredential(targetOU, pwd); 141516 string dn = ""; 1718 //ldapConnection = new LdapConnection(new LdapDirectoryIdentifier(ldapServer)); 19 //ldapConnection.SessionOptions.ProtocolVersion = 3;//Ldap协议版本 20 //ldapConnection.AuthType = AuthType.Anonymous;//不传递密码进行连接2122 ldapConnection = new LdapConnection(ldapServer); 23 ldapConnection.AuthType = AuthType.Basic; 24 ldapConnection.Credential = credential; 2526 try27 { 28 Console.WriteLine("链接 .");29 ldapConnection.Bind(); 30 Console.WriteLine("链接成功"); 3132 }33 catch (Exception ee)34 {35 Console.WriteLine(ee.Message);