C# 目录条目“;“服务器不可操作”;正在尝试查询远程服务器

C# 目录条目“;“服务器不可操作”;正在尝试查询远程服务器,c#,asp.net,asp.net-mvc,asp.net-mvc-4,directoryservices,C#,Asp.net,Asp.net Mvc,Asp.net Mvc 4,Directoryservices,我试图查询需要建立VPN连接(以便访问服务器)的远程Active Directory服务器。下面是我的代码片段: DirectoryEntry adsEntry = new DirectoryEntry(); adsEntry.Username = "user_name"; adsEntry.Password = "password"; adsEntry.AuthenticationType = AuthenticationTypes.Secure; adsEntry.Path = "LDAP:

我试图查询需要建立VPN连接(以便访问服务器)的远程Active Directory服务器。下面是我的代码片段:

DirectoryEntry adsEntry = new DirectoryEntry();
adsEntry.Username = "user_name";
adsEntry.Password = "password";
adsEntry.AuthenticationType = AuthenticationTypes.Secure;
adsEntry.Path = "LDAP://domain.com:636/CN=John Doe,DC=staff,DC=com";

DirectorySearcher adsSearcher = new DirectorySearcher(adsEntry);
adsSearcher.PropertiesToLoad.Add("cn");

try
{
    SearchResult adsSearchResult = adsSearcher.FindOne();
    <p>cn: @adsSearchResult.Properties["cn"][0].ToString()</p>
    adsEntry.Close();
}
catch (Exception ex)
{
    adsEntry.Close();
}
DirectoryEntry=newdirectoryEntry();
adsEntry.Username=“user\u name”;
adscentry.Password=“Password”;
adsEntry.AuthenticationType=AuthenticationTypes.Secure;
adscentry.Path=“LDAP://domain.com:636/CN=johndoe,DC=staff,DC=com”;
DirectorySearcher adsSearcher=新的DirectorySearcher(adsEntry);
adsSearcher.PropertiesToLoad.Add(“cn”);
尝试
{
SearchResult=adsSearcher.FindOne();
cn:@adsSearchResult.Properties[“cn”][0].ToString()

adscentry.Close(); } 捕获(例外情况除外) { adscentry.Close(); }
例外情况是:

System.Runtime.InteropServices.COMException(0x8007203A):服务器 不可操作。在 System.DirectoryServices.DirectoryEntry.Bind(布尔throwIfFail)位于 System.DirectoryServices.DirectoryEntry.Bind()位于 System.DirectoryServices.DirectoryEntry.get\u AdsObject()位于 System.DirectoryServices.DirectorySearcher.FindAll(布尔值 在……处找到(不止一个) System.DirectoryServices.DirectorySearcher.FindOne()位于 第37行中的ASP.\页面\视图\广告\ cshtml.Execute()

我知道有很多关于“服务器无法运行”错误的帖子,但我的具体问题是,当我在另一个域上时,这个错误是否与VPN连接有关?当连接到VPN时,我能够使用Softerra LDAP浏览器浏览广告,使用的路径和凭据与我在上面的代码片段中使用的相同。关闭VPN后,我可以使用相同的代码(尽管路径和凭据不同)访问我的本地广告而不会出错

注意:我相信基于端口的AuthenticationTypes应该是安全的,但我尝试了所有选项,结果都是一样的


提前谢谢

我已经看到了一个类似的问题—除去VPN—通过添加一个映射到原始服务器上的目标域的静态主机条目来解决。在您的情况下,在运行代码:x.x.x.x domain.com的服务器上,这不会回答您的问题,但您的exceptin表示此代码在视图中。不要这样做-将您的逻辑保存在控制器或某种服务层中。端口表明确实存在安全连接。您是否尝试使用ip而不是域名?由于您不在域名上,解决域名可能会有一些问题。@DavidG同意。只是删除了一个最终将驻留在controller中的代码片段。@StfBln尝试了ip,但结果相同。多篇在线帖子都提到通过VPN的LDAP是一个问题。检查以下可能提供更多信息的内容:和