.net - c# 通过 ssl 连接到 Active Directory 使 ldap 服务器不可用

标签 .net ssl active-directory ldapconnection

我正在尝试使用 .net System.DirectoryServices.Protocols namespace api 通过 ssl 连接到事件目录

这是我为连接到事件目录而编写的片段

LdapConnection ldapConnection = new LdapConnection(new LdapDirectoryIdentifier("<ipaddress>:<port>"));
ldapConnection.AuthType = AuthType.Basic;

LdapSessionOptions options = ldapConnection.SessionOptions;
options.SecureSocketLayer = true;
options.ProtocolVersion = 3;

X509Certificate cert = new X509Certificate();
cert.Import(@"E:\client.crt");

ldapConnection.ClientCertificates.Add(cert);
ldapConnection.Credential = new NetworkCredential("administrator", "xxxxxxxxxx");

ldapConnection.Bind();
Console.WriteLine("successfully connected");

当我尝试执行此代码段时,我总是收到 LDAP 服务器不可用错误。我已经为此编写了一个 JAVA 等效程序,它能够连接到服务器,所以我认为证书或事件目录连接没有问题。我也可以使用相同的 IP 地址和端口 389,在没有 ssl 的情况下连接到 Active Directory。

谢谢

最佳答案

LdapConnection ldapConnection = new LdapConnection(server + ":" + port);
ldapConnection.AuthType = AuthType.Basic;
ldapConnection.Credential = new System.Net.NetworkCredential(username,
                                                                  password);
ldapConnection.SessionOptions.ProtocolVersion = 3;
if (sslEnabled)
{
    ldapConnection.SessionOptions.SecureSocketLayer = sslEnabled;
}

这就是我所做的,我能够通过 SSL 连接到 AD。你说你有 Java 程序通过 SSL 连接到同一台服务器。您是否在与 C# 相同的机器上运行 Java 程序?如果不是,如果是 AD 中的自签名证书,请在您的客户端计算机上安装该证书并尝试。

关于.net - c# 通过 ssl 连接到 Active Directory 使 ldap 服务器不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18555600/

相关文章:

.net - 什么对象应该从数据访问层返回到业务层一个n层系统

ssl - 在 Safari 和 websockets (osx/ios) 中使用自签名证书

apache - 缺少 SSL 支持的 cloudfoundry 构建包的 SSL 反向代理构建包?

node.js - findUser 函数中的 Active Directory 错误

mysql - 使用 LDAP (AD) 进行 MySQL 身份验证

Powershell AD 用户按名称和 OU 搜索

c# - Azure Web 应用程序 - "HttpClient Unable to connect to the remote server"

c# - Request.UserHostName 实际返回的是什么,是否可以将其转换为我可以获得主机条目的内容?

c# - 在一个对象中初始化一个集合?

python - 如何在 Azure WebJob 中使用 'pip install packages' 来解决包兼容性问题