简体   繁体   中英

DirectoryEntry “The server is not operational” trying to query remote server

I am trying to query a remote Active Directory server that requires a VPN connection be established (in order to access the server). Below is the snippet of my code:

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();
}

And the exception:

System.Runtime.InteropServices.COMException (0x8007203A): The server is not operational. at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) at System.DirectoryServices.DirectoryEntry.Bind() at System.DirectoryServices.DirectoryEntry.get_AdsObject() at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne) at System.DirectoryServices.DirectorySearcher.FindOne() at ASP._Page_Views_AD_cshtml.Execute() in line 37

I know there are many posts around "The server is not operational" error, but my specific question is more around if this error could be related to the VPN connection while I am on another domain? While connected to VPN I am able to use Softerra LDAP Browser to browse the AD using the same path and credentials I am using in the code snippet above. Off VPN I am able to access my local AD without error using same code about (albeit different path and credentials).

Note: I believe the AuthenticationTypes should be Secure based on the port, but I tried all the options with same result.

Thanks in advance!

I've seen a similar issue -minus the VPN- resolved by adding a static hosts entry mapped to the target domain on the originating server. in your case, on the serer running the code: xxxx domain.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM