ValidateCredentials LDAP Server Unavailable

I am currently using the PrincipalContext class to call the ValidateCredentials method to validate user credentials. It worked perfectly with our environment until a rather "strange" error occurred.

var configuration = ConfigurationManager.GetSection("PrincipalContextConfiguration") as PrincipalContextConfigurationSection;
var principalContext = new PrincipalContext(configuration.ContextType, configuration.Name, configuration.Container);
principalContext.ValidateCredentials(userName, password);

configuration.ContextType = "Domain"
configuration.Name = "example.local"
configuration.Container = "CN=Users,DC=example,DC=local"

Above is an example of our current code, simplified for easier viewing. As above, every time we need to verify the credentials, we will create a new PrincipalContext.

The error we have is authentication, which works fine if we provide a valid username and password. But for a particular machine that throws this error, whenever an invalid username and password is provided, an exception is thrown with the message "LDAP server is unavailable."

Can someone point me where I should start looking for the reason for this. It is strange for us that the method only throws this exception when the username and password are incorrect. we test this using PowerShell to call the method.

And I'm not that expert in AD. Thank.

+3
source share

All Articles