【问题标题】:Consistently receive PrincipalServerDownException when calling ValidateCredentials() method调用 ValidateCredentials() 方法时始终收到 PrincipalServerDownException
【发布时间】:2013-09-06 16:12:47
【问题描述】:

我正在尝试使用新的(ish)System.DirectoryServices.AccountManagement 命名空间对 .net 4.0 应用程序中的 AD 用户进行身份验证。我目前正在使用标准 LDAP 进行测试,但我的计划是在解决此问题后切换到 LDAPS。

我的应用程序在不属于目标 AD 域的网络服务器上运行,也不受信任。我确实有一条到 AD 服务器的网络路由,并且有一个可以用来查询它的有效服务帐户。必要的端口也已打开(LDAP 为 389,LDAPS 为 636)。我可以使用 LDAPExplorerTool 2 和我在下面指出的路径/凭据 (http://ldaptool.sourceforge.net/) 成功地从网络服务器绑定和查询 AD 服务器。

在下面的代码中,我在尝试创建上下文时总是收到 PrincipalServerDownException(无法联系服务器)。出于测试目的,目前省略了 Try/catch 块和其他必需品。


string server = "adServer.mydomain.com:389"; // Properly resolves to IP of AD server
string path = "dc=mydomain,dc=com";
string serviceUser = "username"; // Username in SAM format - no prefix/suffix
string servicePassword = "password";
string username = "loginuser"; // Username in SAM format - no prefix/suffix
string password = "password";

using (PrincipalContext context = new PrincipalContext(ContextType.Domain, server, path, ContextOptions.Negotiate, serviceUser, servicePassword)) { return context.ValidateCredentials(username, password, ContextOptions.Negotiate); }


更新

我尝试使用 LDAPExplorer 工具和上面的代码进行身份验证,而我的网络管理员使用 wireshark 捕获流量。他确定在代码运行时没有收到来自网络服务器源 IP 的数据包。

【问题讨论】:

  • 试试 SimpleBind 作为你的上下文选项怎么样?
  • 感谢您的提示。我试了一下,但还是没有骰子。抛出相同的异常。

标签: c# .net-4.0 active-directory directoryservices


【解决方案1】:

我已经确定了原因。

事实证明,我是从包含上述逻辑的自定义成员资格提供程序的配置属性中获取服务器和路径的值。我没有在我的提供程序的 Initialize() 方法中正确加载这些属性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-02
    • 2020-07-30
    • 1970-01-01
    • 1970-01-01
    • 2021-07-14
    相关资源
    最近更新 更多