简体   繁体   中英

C# ASP.NET application using ldap for authentication

Trying to authenticate through ldap using LdapDirectoryIdentifier to communicate to an openldap server.

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. But upon reviewing my.netstat, the connection is there and established. 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):

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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