1

My application is using the AD Authentication for Login using LDAP URL. All was fine until our SA told us to change the URL to LDAPS. Once I added the URL as LDAPS it throws an exception and does not allow users to Login. Please help me in this.

Working LDAP URL: LDAP://reg1.abc.com
LDAPS URL (NEW) : LDAPS://reg1.abc.com (Not working once changed)

Below is the code to Authenticate user through LDAP.

    public static SearchResult AuthenticateUser(string userName, string password)
    {
        var directoryEntry = new DirectoryEntry(ConfigurationManager.AppSettings["ActiveDirectoryPath"], userName, password, AuthenticationTypes.Secure);
        var directorySearcher = new DirectorySearcher(directoryEntry);
        directorySearcher.Filter = "(samaccountname=" + userName + ")";
        var result = directorySearcher.FindOne();
        return result;
    }
vsriganan
  • 51
  • 1
  • 9

1 Answers1

2

That's a common question that might be already answered at Unknown Error (0x80005000) with LDAPS Connection. Follow that link and try to add port 636 and custom certificate validation:

LdapConnection con = new LdapConnection(new LdapDirectoryIdentifier("server", port));
con.SessionOptions.SecureSocketLayer = true;
con.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback(ServerCallback);
con.Credential = new NetworkCredential(String.Empty, String.Empty);
con.AuthType = AuthType.Basic;
con.Bind();

In the given example Credential is using empty strings, that might need to be changed by real login/password if required.

Community
  • 1
  • 1
user2316116
  • 6,726
  • 1
  • 21
  • 35