DirectoryEntry "The server is not operational" trying to query remote server

0

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!

c#
asp.net
asp.net-mvc
asp.net-mvc-4
directoryservices
asked on Stack Overflow Mar 14, 2017 by OtoNoOto

1 Answer

1

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: x.x.x.x domain.com

answered on Stack Overflow Sep 21, 2017 by Manuel Montes

User contributions licensed under CC BY-SA 3.0