Need to connect as gis admin service account from C#

690
2
07-31-2017 06:02 AM
DavidWendelken
Occasional Contributor

We recently switched an ESRI webserver to use the https protocol and (unhappily!) discovered that the https://MyEsriUrl/arcgis/rest/services?f=sitemap command did not return data unless the active directory user had the GIS admin privileges.

So, my intended solution to this is to create a C# webservice to receive a parameter of https://MyEsriUrl/arcgis/rest/services?f=sitemap, which will connect to the ESRI webserver using an active directory service account that has the necessary GIS privileges.  It will receive the sitemap info and return it to the user.

(See https://community.esri.com/thread/198410-httpsmyesriurlarcgisrestservicesfsitemap-doesnt-work#commen... ) for more details on the original problem.)

There are a bazillion ways to pass security credentials and I just want to use the right way the first time, or at least find it while I still have hair that hasn't been pulled out.  

Here's some sample code:

public XmlDocument GetSiteMap (string url)
{
  Uri uri = new Uri(url);
  string user = "domain\\user";
  string pwd = "thepassword";
  HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest;
  // some magic happens here...
  using(HttpWebResponse response = request.GetResponse() as HttpWebResponse)
  {
     // I do my stuff here, no problem at this point.
  }     
}

Here's one approach I used to supply the magic needed:

// some magic happens here...
request.PreAuthenticate = true;

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
CredentialCache credentialCache = new CredentialCache();
credentialCache.Add(uri, "Basic", new NetworkCredential(user, pwd));
request.Credentials = credentialCache;


No luck.  If I log on to the computer using the user/pwd and make the sitemap call in the browser I get back sitemap data.  But using the same credentials as above I get back an empty sitemap.


0 Kudos
2 Replies
DavidWendelken
Occasional Contributor

Well, instead of Basic mode I've tried Digest, NTLM and Negotiate.   Same empty sitemap.  On to other attempts.

0 Kudos
DavidWendelken
Occasional Contributor

Apparently when an ESRI webserver is federated to an ESRI GIS portal, the portal takes over security behind the scenes.  So I'm downloading the .Net DLLs so I can try getting and sending a token.  

0 Kudos