2016-08-25 196 views
1

尝试使用LdapDirectoryIdentifier通过ldap进行身份验证以与openldap服务器进行通信。使用ldap进行身份验证的C#ASP.NET应用程序

代码片断

  dapDirectoryIdentifier ldi = new LdapDirectoryIdentifier("ldap.com", 636); 
      LdapConnection lconn = new LdapConnection(ldi); 
      lconn.SessionOptions.ProtocolVersion = 3; 
      lconn.Bind(); 
      lconn.Dispose(); 

运行代码给了我一个异常的bind()的说明LDAP服务器不可用。但在查看我的netstat后,连接就建立了。没有其他错误消息可用。

有什么想法?

回答

1

端口636适用于SSL。直接与LdapConnection尽量确保您可以通过SSL(SecureSocketLayer =真)访问该服务器:

using (var ldapConnection = new LdapConnection("my.ad.server:636")) { 
        var networkCredential = new NetworkCredential(username, password, "my.ad.server"); 
ldapConnection.SessionOptions.SecureSocketLayer = true; 
        ldapConnection.AuthType = AuthType.Negotiate; 
        ldapConnection.Bind(networkCredential); 
       } 

见,如果这个工程。

+1

这部分是答案。也没有证书,所以我不得不绕过使用lconn.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback((con,ver)=> true); – adroit

相关问题