我有以下代码来验证Active Directory用户(Win7上的VS2008)。
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);
}
对于某些AD用户,没关系,但对于AD用户,我将收到以下异常:
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)
Active Directory域用户设置是否会导致此类异常?
答案 0 :(得分:1)
抱歉,我上面的描述错了。事实上,所有AD用户验证都会遇到此类异常。
工作环境是: (1)如果验证码在完全是AD机器的机器上运行,则代码将获得此类异常。 (2)否则,没有这样的例外。
为ValidateCredentials附加ContextOptions.Negotiate参数以解决问题。