[GIS] Arcgis basemap with proxy.ashx not loading correctly

arcgis-javascript-apiarcgis-online-basemapsPROXY

I have a .Net application using the JavaScript API to draw a map. I use the proxy.ashx file to proxy requests to secure map services (dynamic tokens), configured in proxy.config. I added an entry into proxy.config for ArcGIS Online:-

<serverUrl url="http://services.arcgisonline.com/" matchAll="true" />

My JavaScript is as follows:-

    esri.config.defaults.io.alwaysUseProxy = true;
    esri.config.defaults.io.proxyUrl = "/proxy.ashx";

    map = new esri.Map("map", {
        extent: new Extent({
            xmin:174.5, ymin:-39, xmax:174.7, ymax:-38.8,
            spatialReference:{wkid:4326}
        }),
        basemap: "topo"
    });

If I exclude the basemap, my map draws as expected but if I include the basemap (as above), the basemap is drawn partially and I get an infinite loop of null requests occurring:

    GET /proxy.ashx?undefined/tile/NaN/NaN/NaN?blankTile=false HTTP/1.1

I have stripped out all other code to eliminate that as a cause. If I comment out the two lines of JavaScript to use the proxy the basemap works perfectly so the problem has something to do with my proxy.config and/or the proxy.ashx file. Possibly I have an older version old proxy.ashx.

Has anyone seen this error before, or point me in the right direction to get a basemap working with the proxy configuration? I am using JavaScript API 3.8

Best Answer

not a direct answer to your question, but since you're using version 3.8 of the API, you can selectively route traffic to secure services through your proxy rather than relying on setting alwaysUseProxy to 'true'.

instead of

esri.config.defaults.io.alwaysUseProxy = true;

you could use

urlUtils.addProxyRule({
    urlPrefix: "traffic.arcgis.com",  
    proxyUrl: "/sproxy"
});

https://developers.arcgis.com/javascript/jsapi/esri.urlutils-amd.html#addproxyrule

see this sample for an example in action: https://developers.arcgis.com/javascript/jssamples/widget_directions_basic.html