Problems using Proxy.ashx with ArcGisOnline Base Map

1029
2
10-03-2013 10:25 AM
AlpineTech
New Contributor III
I have a proxy.ashx setup on the company's web server to proxy AGS requests.  It has worked fine for several months with the AGS Flex API.  Now I want to build a Javascript viewer to replace the Flex API viewer, using the same proxy.ashx.  The first thing I noticed is there is a difference between how the Flex API and the Javascript API use Proxy.ashx.  In the Flex API you set the "proxyUrl" per map service, but in the Javascript API it is a global setting for the entire application.  The Flex API works very well because you can use the proxy.ashx for internal operational layers from a company's AGS and not use the proxy.ashx for ArcGISOnline base maps.  Still, the Javascript API appears to provide a way to accomplish the same thing, but in a different way.  If I understand this correctly, I can use proxy.ashx for our internal AGS this way:

esriConfig.defaults.io.alwaysUseProxy = true;
esri.config.defaults.io.proxyUrl = "http://mywebserver.mycompany.com/agsproxy/proxy.ashx";
esriConfig.defaults.io.urlPrefix = "myags.mycompany.com";

So I did and it works fine since I get the layers from the company AGS.  However, I don't get the ArcGISOnlie basemap layers because those requests were also proxied through the proxy.ashx, which caused them to fail. Still, the Javascript API docs say use the corsEnabledServers to fix that problem so I added this line:

esri.config.defaults.io.corsEnabledServers.push("services.argisonline.com");

Which solved the problem for the first request to arcgisonline, but all others after the first fail in IE, Chrome and Firefox.   Perhaps I'm doing something wrong?
0 Kudos
2 Replies
JohnGravois
Frequent Contributor
in version 3.4 of the API we added useProxyRule() as a technique to direct specific requests through a proxy.  see this sample for a demonstration of the technique in action.
0 Kudos
AlpineTech
New Contributor III
Tried it.  So far so good.  Thanks.
0 Kudos