locked
LDAP connection - server is not operational RRS feed

  • Question

  • User1151108763 posted

    Hello, I am trying to connect to the LDAP server and my goal is to change user password through the application. My working application is hosted inside the domain and the following code works fine to change password.

    using (PrincipalContext principalContext = new PrincipalContext
    (ContextType.Domain, DomainName, DomainDN, ContextOptions.Negotiate, AdminUserName, AdminUserPassword))
    {
    UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(principalContext, IdentityType.SamAccountName, userName);
    dnuser = userPrincipal.DistinguishedName;
    currentdc = principalContext.ConnectedServer;
    DirectoryEntry directoryEntry = (DirectoryEntry)userPrincipal.GetUnderlyingObject();
    userPrincipal.ChangePassword(oldPassword, newPassword);

    userPrincipal.Dispose();

    }

    Now I need to move the application to a new server which is outside the domain (DMZ server) of the DC. So I am having to use LDAP connection over SSL. I am trying to connect to the LDAP server with the following code but getting error "The server is not operational" on the line deSearch.FindOne().

    string ldapString = "LDAP://123.45.678.123:636/DC=mydomain,DC=com";

    DirectoryEntry de = new DirectoryEntry(ldapString, adminUser, adminPass, AuthenticationTypes.Secure);
    //DirectoryEntry de = new DirectoryEntry(ldapString, adminUser, adminPass);
    DirectorySearcher deSearch = new DirectorySearcher(de) { SearchRoot = de, Filter = "(&(objectCategory=user)(cn=" + "xar22" + "))" };

    var directoryEntry = deSearch.FindOne();

    Can someone please help me understanding what I am doing wrong?

    Thanks!

    Thursday, October 17, 2019 12:26 AM

All replies