我已经用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。
但是
在以上所有情况下提供的凭据都是相同的。
我无法弄清楚为什么无法从本地计算机上运行控制台应用程序。
请帮助。
答案 0 :(得分:0)
我能够通过在主机文件中添加AD LDS服务器的IP地址和主机名的条目来解决此问题