0
votes

I am working on a requirement where I need to validate user with active directory account. For this I have used LdapConnection with NetworkCredential and PrincipalContext and in all cases I am able to validate user without SSL. But I need to use validate user with SSL. I have also used the correct port i.e 636/TCP LDAP SSL

Following is the code I did with PrincipalContext

using (principalContext = new PrincipalContext(ContextType.Domain, ldapServerIp, null, ContextOptions.Negotiate | ContextOptions.SecureSocketLayer, userName, password))
                { bool isCredentialValid = principalContext.ValidateCredentials(userName, password);}

Following is code I did with

using (ldapConnection = new LdapConnection(ldapServerIp))
                {
                    var networkCredential = new NetworkCredential(_username, _password, ldapServerIp);
                    ldapConnection.SessionOptions.SecureSocketLayer = true;
                    ldapConnection.AuthType = AuthType.Negotiate;
                    ldapConnection.Bind(networkCredential);

                }

Does anyone have did this earlier successfully. If there is any solution that will be very helpful.

1

1 Answers

1
votes

Both of those should work just fine, as long as you specify the LDAPS port (usually 636). So your ldapServerIp variable should be set to something like example.com:636.