2

I have the following code to verify a Active Directory user(VS2008 on Win7).

try
{
    PrincipalContext pc = new PrincipalContext(ContextType.Domain, strDomainName))
    isPass = pc.ValidateCredentials(strDomainUserName, strDomainUserPass);
}
catch (Exception ex)
{
    Logger.Log("authentiate domain user fail: {0},{1}", ex.ToString(), strDomainUserLoginName);
}

For some AD user, it is OK, but for a AD user, I will get the following exception: System.DirectoryServices.Protocols.DirectoryOperationException: The server cannot handle directory requests.

System.DirectoryServices.Protocols.ErrorChecking.CheckAndSetLdapError(Int32 error)

System.DirectoryServices.Protocols.LdapSessionOptions.FastConcurrentBind()

System.DirectoryServices.AccountManagement.CredentialValidator.BindLdap(NetworkCredential creds, ContextOptions contextOptions)

System.DirectoryServices.AccountManagement.CredentialValidator.Validate(String userName, String password)

System.DirectoryServices.AccountManagement.PrincipalContext.ValidateCredentials(String userName, String password)

So does Active Directory Domain user setting will cause such a exception?

user2090362
  • 41
  • 1
  • 6
  • Check out the solution on this posting http://stackoverflow.com/questions/2473222/validatecredentials-returns-false-on-first-call-but-true-on-subsequent-calls – MethodMan Feb 20 '13 at 09:03
  • also you can look at this Stackoverflow posting I believe it will answer your question.. http://stackoverflow.com/questions/9473314/active-directory-principalcontext-validatecredentials-domain-disambiguation – MethodMan Feb 20 '13 at 09:04

1 Answers1

1

Sorry, my description above is wrong. In fact, all AD user verification will get such exception.

And the working environment is: (1) If the verification code is running on the machine which is exactly the AD machine, then the code will get such exception. (2) Otherwise, there has no such exception.

Append ContextOptions.Negotiate parameter for ValidateCredentials to resolve the problem.

user2090362
  • 41
  • 1
  • 6