0

我正在尝试使用以下代码对 LDAP 用户进行身份验证。

using (PrincipalContext context = new PrincipalContext(ContextType.Domain, ldap, "username", "password"))
{
    bool success = context.ValidateCredentials(useralias, password);
}

当我将 ldap 用作“LDAP://zyorg:389/”时,我在 PrincipalContext 初始化时收到“无法联系服务器”的错误消息。

如果我将 ldap 用作“zyorg:389/”,则如果我使用正确的凭据,则步骤成功,并且成功为“true”,但是当 ValidateCredentails 执行时,我可以在“IntelliTrace”中看到两个异常,即“LDAP 服务器不可用”。如果我为此方法提供了错误的凭据,如果得到错误但仍然会在“IntelliTrace”中记录相同的异常。

非常感谢任何解决问题或调试正在发生的事情的指针。

4

1 回答 1

0

如果要进行身份验证,可以使用 PrincipalContext 使用以下步骤:

using(var context = new PrincipalContext(ContextType.Domain, "mydomain", "mydomain\serviceAcct", "serviceAcctPass")) 
{
     //Username and password for authentication.
     return context.ValidateCredentials(username, password);      
}

serviceAcct” = 域用户中具有目录查找权限的帐户。“ serviceAcctPass ” = 该服务帐户的密码。正如我所说,对于测试,您可以尝试使用自己的用户/通行证上下文。

此外,请确保提供的用户名具有“域\用户名”或“用户名@域”格式。

于 2015-08-11T05:58:46.737 回答