简体   繁体   English

C# ASP.NET 应用程序使用 ldap 进行身份验证

[英]C# ASP.NET application using ldap for authentication

Trying to authenticate through ldap using LdapDirectoryIdentifier to communicate to an openldap server.尝试使用 LdapDirectoryIdentifier 通过 ldap 进行身份验证以与 openldap 服务器通信。

Code snippet代码片段

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

Running the code gives me an exception at Bind() stating LDAP server is not available.运行代码在 Bind() 处出现异常,说明 LDAP 服务器不可用。 But upon reviewing my.netstat, the connection is there and established.但是在查看 my.netstat 后,连接就在那里并建立了。 There are no other error messages available.没有其他可用的错误消息。

Any idea?任何的想法?

Port 636 is for SSL. Try directly with LdapConnection to make sure you can access that server via SSL (SecureSocketLayer = true):端口 636 用于 SSL。直接尝试使用 LdapConnection 以确保您可以通过 SSL (SecureSocketLayer = true) 访问该服务器:

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);
                }

See if this works.看看这是否有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM