I have developed a console application in C# to connect to an AD LDS server. The console app is a simple app with the following code
PrincipalContext context = new PrincipalContext(ContextType.ApplicationDirectory, <<AD LDS IP Address>>, <<CONTAINER>>, <<USER>>, <<PASSWORD>>);`
bool validate = context.ValidateCredentials("CN=" + <<SOME_USER>> + "," + <<CONTAINER>>, <<SOME_USER_PASSWORD>>, ContextOptions.SimpleBind);
The ValidateCredentials method fails with the following error
System.DirectoryServices.AccountManagement.PrincipalServerDownException: The server could not be contacted. ---> System.DirectoryServices.Protocols.LdapException: The LDAP server is unavailable.
at System.DirectoryServices.Protocols.LdapConnection.Connect()
at System.DirectoryServices.Protocols.LdapConnection.SendRequestHelper(DirectoryRequest request, Int32& messageID)
at System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest request, TimeSpan requestTimeout)
at System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest request)
at System.DirectoryServices.AccountManagement.PrincipalContext.ReadServerConfig(String serverName, ServerProperties& properties)
--- End of inner exception stack trace ---
at System.DirectoryServices.AccountManagement.PrincipalContext.ReadServerConfig(String serverName, ServerProperties& properties)
at System.DirectoryServices.AccountManagement.PrincipalContext.DoServerVerifyAndPropRetrieval()
at System.DirectoryServices.AccountManagement.PrincipalContext..ctor(ContextType contextType, String name, String container, ContextOptions options, String userName, String password)
at System.DirectoryServices.AccountManagement.PrincipalContext..ctor(ContextType contextType, String name, String container, String userName, String password)
at ConsoleLDAP.Program.AuthenticateAD() in C:\Users\Rajesh\Desktop\ConsoleLDAP\ConsoleLDAP\Program.cs:line 84
I am running this program from my local machine. The AD LDS is server is located remotely and so I am using VPN.
However,
- When I run the console app in the same server where AD LDS is installed, the app connects to the AD LDS.
- When I try to RDP from my local machine over VPN to the AD LDS server, the RDP connects.
- When I run ADExplorer from my local machine over VPN, I am able to connect to the AD LDS.
The credentials provided are same in all the above scenarios.
I am unable to figure out why I cannot make the console app work from my local machine.
Please help.