Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用LDAPS身份验证时出现LDAP服务器不可用错误_C#_Ssl_Active Directory_Ldap_Ssl Certificate - Fatal编程技术网

C# 使用LDAPS身份验证时出现LDAP服务器不可用错误

C# 使用LDAPS身份验证时出现LDAP服务器不可用错误,c#,ssl,active-directory,ldap,ssl-certificate,C#,Ssl,Active Directory,Ldap,Ssl Certificate,行con.bind()中出现错误,说明LDAP服务器不可用。相同的代码在端口389上运行正常,但在636上运行不正常,即LDAPS636使用TLS/SSL对证书进行加密,而389不使用证书。TLS有很多版本,因此服务器可能正在使用TLS模式。请参阅:。端口号636也可能被阻止。@jdweng-我在代码行中还发现了一件重要的事情:con.SessionOptions.SecureSocketLayer=true;它没有设置为true,但该值始终保持为“false”。此外,我还尝试使用ADExplo

行con.bind()中出现错误,说明LDAP服务器不可用。相同的代码在端口389上运行正常,但在636上运行不正常,即LDAPS

636使用TLS/SSL对证书进行加密,而389不使用证书。TLS有很多版本,因此服务器可能正在使用TLS模式。请参阅:。端口号636也可能被阻止。@jdweng-我在代码行中还发现了一件重要的事情:con.SessionOptions.SecureSocketLayer=true;它没有设置为true,但该值始终保持为“false”。此外,我还尝试使用ADExplorer进行连接。LDAP很容易通过端口636进行连接,但无法使用我的dotnet代码进行连接。不安全的389服务可能没有查看SessionOptions。SecureSocketLayer=true;但我在389端口上没有问题,我在636端口上有LDAP问题。要使其正常工作,SessionOptions.SecureSocketLayer=true;必须是有效的。是否有任何方法可以进行更深入的调查,而不是获取一般性错误“LDAP服务器不可操作”用于下载服务器正在发送的证书。使用
https://example.com:636
作为URL(其中
example.com
是您的域名)。它将把证书保存为一个.cer文件,您可以双击该文件进行检查。
string username = "username";
var con = new LdapConnection(new LdapDirectoryIdentifier(ADUtilities.LDAPServer, Convert.ToInt32(ADUtilities.LDAPPort), false, false));
con.SessionOptions.SecureSocketLayer = true;
con.SessionOptions.ProtocolVersion = 3;
var clientCertificateFile = new X509Certificate();
clientCertificateFile.Import(ADUtilities.LDAPSSLCertificatePath);
con.ClientCertificates.Add(clientCertificateFile);
con.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback(VerifyServerCertificate); }

con.Credential = new NetworkCredential(username, ADPassword);
con.AuthType = AuthType.Negotiate;
con.Timeout = new TimeSpan(0, 1, 0);
con.Bind();
private bool VerifyServerCertificate(LdapConnection ldapConnection, X509Certificate certificate) {
    X509Certificate2 certificate2 = new X509Certificate2(certificate);
    return certificate2.Verify();
}