ThinkGeo.com    |     Documentation    |     Premium Support

ArcGISServerRestLayer user name and password

We’re looking into using the ArcGISServerRestLayer to bring in ESRI maps and it’s working ok for the sample url. However, I haven’t figured out how to add a user name / password to access a protected url. Is that possible with the parameters that are passed to the ArcGISServerRestLayer and if so how is it done?

Thanks,
Neil

Hi Neil,

I viewed the document of ArcGIS REST api here: https://developers.arcgis.com/rest/services-reference/export-tiles-map-service-.htm

It looks this topic hadn’t talked about the username and password.

But I think it should be looks like this as below:

  1. Attach user name and password in the request link as parameters
  2. Attach the token in request link as parameter

I think you can view their document to make sure that or did test by manual modify a url link.

After that you can write code in the SendingWebRequest event to make each request can pass the server side validation.

Wish that’s helpful.

Regards,

Ethan

Do you have any sample code for the SendingWebRequest event? I’ve set up an account on arcgis.com but I’m not sure if I’m using that function to access the site correctly. I’m using the ArcGISServerRestLayer and have tried the arcgis link (https://arcg.is/18qnPb0) as well as this link (https://www.arcgis.com/sharing/rest/generateToken) to generate a token. Neither of them seem to return anything that I can use when the SendingWebRequest event is handled. The SendingWebRequest event is fired twice and then I get this:

System.Net.WebException: ‘The remote server returned an error: (400) Bad Request.’

Thanks,
Neil

Hi Neil,

We have a sample here: https://github.com/ThinkGeo/ArcGISServerRestLayerSample-ForWPF

documentation for ArcGIS Server REST API can be found at: http://resources.arcgis.com/en/help/arcgis-rest-api/ , V9.3: http://resources.esri.com/help/9.3/arcgisserver/apis/rest/index-9-3.html

You can add the SendingWebRequest event like this:

    arcGisLayer.SendingWebRequest += ArcGisLayer_SendingWebRequest;

    private void ArcGisLayer_SendingWebRequest(object sender, SendingWebRequestEventArgs e)
    {
        string requestUri = e.WebRequest.RequestUri.ToString();
    }

Then you can copy the requestUri to browser and see whether any parameter missed.

I hope that’s helpful.

Regards,

Ethan

That sample does work fine for me, but the problem I’m having is when I need to pass a user name and password. I’ve tried a few different things with the token that is generated by Arcgis but I’m still getting a “Parameter is not valid” message. Do you have an example for a situation that requires a login?

Thanks,
Neil

Hi Neil,

I read some documents of ArcGis restful service today, here is about the map export service: https://developers.arcgis.com/rest/services-reference/export-map.htm

I hadn’t found description about token in it. So I want to make sure what’s service you are using, and could you please let us know how to test it, document link about that should also helpful.

In our sample it require export map from http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/export, so the requested link looks like:

http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/export?BBOXSR=3857&IMAGESR=3857&FORMAT=png&TRANSPARENT=true&LAYERS=show:2&LAYERDEFS=2:POP1999>+50000&BBOX=-10648031.0711787%2C1875411.57348982%2C-8143342.54224495%2C4380100.10242355&SIZE=256%2C256&F=image

You can directly view it on browser.

I think for your service it should have an URL to access it online, so we can see how the parameter need to be added in request and add it to the code like other parameters, for example:
arcGisLayer.Parameters.Add(“bboxSR”, “3857”);

Any information please feel free to let us know

Regards,

Ethan

I’ve created a developer account on arcgis.com and generated a map that I can access with this link: https://arcg.is/0PbiaW. Right now it’s password protected, so I have to log in in order to view it. I’ve tried setting the user name and password on the ArcGISServerRestLayer as well as generating a token and sending that along as a parameter but so far that hasn’t worked. I’m generating the token by following the process described here: https://developers.arcgis.com/labs/rest/get-an-access-token/.

Hi Neil,

I think your map is not work for the rest API.

Because your link contains “viewer”, I think that’s for another product “ArcGIS Online”, and you should create the map like this:

But for rest API the guides is the other topics:

And this service is based on the access token:

So I think you should want to create the service follow the guide for export a map. And then you can try to render it via our map.

I hope that’s helpful.

Regards,

Ethan