我在 C# 中开发了一个控制台应用程序来连接到 AD LDS 服务器。控制台应用程序是一个简单的应用程序,代码如下
PrincipalContext context = new PrincipalContext(ContextType.ApplicationDirectory, <<AD LDS IP Address>>, <<CONTAINER>>, <<USER>>, <<PASSWORD>>);`
bool validate = context.ValidateCredentials("CN=" + <<SOME_USER>> + "," + <<CONTAINER>>, <<SOME_USER_PASSWORD>>, ContextOptions.SimpleBind);
ValidateCredentials 方法失败并出现以下错误
System.DirectoryServices.AccountManagement.PrincipalServerDownException: The server could not be contacted. ---> System.DirectoryServices.Protocols.LdapException: The LDAP server is unavailable.
at System.DirectoryServices.Protocols.LdapConnection.Connect()
at System.DirectoryServices.Protocols.LdapConnection.SendRequestHelper(DirectoryRequest request, Int32& messageID)
at System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest request, TimeSpan requestTimeout)
at System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest request)
at System.DirectoryServices.AccountManagement.PrincipalContext.ReadServerConfig(String serverName, ServerProperties& properties)
--- End of inner exception stack trace ---
at System.DirectoryServices.AccountManagement.PrincipalContext.ReadServerConfig(String serverName, ServerProperties& properties)
at System.DirectoryServices.AccountManagement.PrincipalContext.DoServerVerifyAndPropRetrieval()
at System.DirectoryServices.AccountManagement.PrincipalContext..ctor(ContextType contextType, String name, String container, ContextOptions options, String userName, String password)
at System.DirectoryServices.AccountManagement.PrincipalContext..ctor(ContextType contextType, String name, String container, String userName, String password)
at ConsoleLDAP.Program.AuthenticateAD() in C:\Users\Rajesh\Desktop\ConsoleLDAP\ConsoleLDAP\Program.cs:line 84
我正在本地机器上运行这个程序。AD LDS 是服务器位于远程,所以我使用 VPN。
然而,
- 当我在安装 AD LDS 的同一服务器上运行控制台应用程序时,该应用程序连接到 AD LDS。
- 当我尝试通过 VPN 从本地计算机到 AD LDS 服务器的 RDP 时,RDP 连接。
- 当我通过 VPN 从本地计算机运行 ADExplorer 时,我能够连接到 AD LDS。
提供的凭据在上述所有场景中都是相同的。
我无法弄清楚为什么我不能让控制台应用程序在我的本地机器上工作。
请帮忙。