Resource proxy Url not pre-pending to request Url (4x)

710
8
10-02-2019 10:47 AM
DirkVandervoort
Occasional Contributor II

Below is simple code to add a secure webmap into a MapView. This issue is that the proxy URL in not pre-pending to the Portal item URL. Instead I get the login dialog. 

I expect to see a URL like this in my network traffic:

https://MY_PROXY_URL/EsriResourceProxy/proxy.ashx?https://MY_PORTAL_URL/portal/sharing/rest/content/... which successfully returns content in the browser. This indicates that the proxy is properly configured and the values in proxy.config are correct.

Instead, I see native URLs like this in my network traffic:

https://MY_PORTAL_URL/portal/sharing/rest/content/items/4b0a97623245423fb3cbdfb321f0970e which informs me that I do not have permissions.

So, my question is: how do I get my JS to format the request Url to be pre-pended with the proxy URL?

TIA

<script>
 require([
 "esri/views/MapView", 
 "esri/WebMap",
 "esri/config"], 
 function(
 MapView, 
 WebMap,
 esriConfig) {
esriConfig.request.proxyUrl = "https://MY_PROXY_DOMAIN/EsriResourceProxy/proxy.ashx";
 
 esriConfig.portalUrl = "https://MY_PORTAL_DOMAIN/portal";
 var webmap = new WebMap({
 portalItem: {
 id: "4b0a97623245423fb3cbdfb321f0970e"
 }
 });
 var view = new MapView({
 map: webmap,
 container: "viewDiv"
 });
 });
 </script>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
8 Replies
BenElan
Esri Contributor

Try adding it as a proxy rule. In the JavaScript app:

urlUtils.addProxyRule({
   urlPrefix: "https://MY_PORTAL_DOMAIN/portal",
   proxyUrl: "https://MY_PROXY_DOMAIN/EsriResourceProxy/proxy.ashx"
}); ‍‍‍‍

In proxy.config:

<serverUrl url="https://MY_PORTAL_DOMAIN/portal"
    username="USERNAME"
    password="PASSWORD"
    matchAll="true"/>‍‍‍‍

Relevant documentation:

Setting up proxy overview 

addProxyRule 

DirkVandervoort
Occasional Contributor II

I tried that as well without success. No joy...

0 Kudos
BenElan
Esri Contributor

In your browser, when you go to:

https://MY_PROXY_DOMAIN/EsriResourceProxy/proxy.ashx?ping

You should get an output like:

{ "Proxy Version": "1.1.2", "Configuration File": "OK", "Log File": "Not Exist/Readable"}

If your proxy is set up correctly. Can you check that?

0 Kudos
DirkVandervoort
Occasional Contributor II

Yes, pinging the proxy returns the expected results. The proxy is configured correctly. Thanks.

0 Kudos
BenElan
Esri Contributor

Are there any errors in the console or network traffic in the browser's dev tools?

0 Kudos
DirkVandervoort
Occasional Contributor II

No errors in console or in network traffic. 

esriConfig.request.proxyUrl and urlUtils.getProxyUrl() both have values i.e., the proxy URL after the proxyUrl has been set 

0 Kudos
BenElan
Esri Contributor

I'd suggest opening a case with Esri Technical Support so an Analyst can take a closer look.

0 Kudos
JackFanZhang
New Contributor III

I had the same issue, in my case, I solved it by using urlUtils.addProxyRule instead of push the rules directly to the esriConfig.requst.proxyRules, this is the way suggested by the API doc

urlUtils.addProxyRule({
   proxyUrl: "https://localhost:8080/proxy",
   urlPrefix: "https://myportaldomain/arcgis/sharing"
})

 

0 Kudos