Select to view content in your preferred language

Proxy and CORS

3162
5
Jump to solution
06-03-2014 07:05 AM
AlexeiB
Occasional Contributor
Hello,

I have established my proxy and have everything running through it on my JS site. Everything seems to be fine in IE but Firefox and Chrome disagree. I am unable to do anything in the map if I am using FF or Chrome. Having gone into dev tools, I see that I get an error "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at <proxy location>.ashx?<web service url> This can be fixed by moving the resource to the same domain or enabling CORS."

My question is, how do you enable CORS? I have added the clause as per here into my .ashx (proxy) web.config but still no luck. Anything else I am missing?

Thank you,
0 Kudos
1 Solution

Accepted Solutions
AlexeiB
Occasional Contributor
I solved my issue and this may help you as well.

In my case, I had my services running on http://abc.xyz.com and I was accessing them from http://def.hij.com. I installed the proxy and was trying to figure out why it wasn't working. It turns out the proxy was located on http://abc.xyz.com and NOT on http://def.hij.com. This obviously is an issue because my hij.com is trying to access a resource located on xyz.com which is a cross origin violation. I moved the proxy to def.hij.com and the problem was solved.

Hope this helps.

Alex

View solution in original post

0 Kudos
5 Replies
IrfanClemson
Occasional Contributor II
I am in the same boat--a  FindTask request fails on non-IE browsers if the index.html or index.aspx files are hosted on the same web server which is hosting the ESRI ArcGIS Server; otherwise, if the files are hosted on my workstation's web server then no problem. I have placed a crossdomain.xml file in the root of the remote web server as well as place a web.config file next to the html/aspx files but still no avail.

ESRI has this: https://developers.arcgis.com/javascript/jssamples/exp_cors_buffer.html

but I think this is too complicated.

Any idea?
Thanks.
0 Kudos
AlexeiB
Occasional Contributor
I solved my issue and this may help you as well.

In my case, I had my services running on http://abc.xyz.com and I was accessing them from http://def.hij.com. I installed the proxy and was trying to figure out why it wasn't working. It turns out the proxy was located on http://abc.xyz.com and NOT on http://def.hij.com. This obviously is an issue because my hij.com is trying to access a resource located on xyz.com which is a cross origin violation. I moved the proxy to def.hij.com and the problem was solved.

Hope this helps.

Alex
0 Kudos
IrfanClemson
Occasional Contributor II
@Koder303,
Glad you got it working!

It's not working for me using proxy. Here is my config:

Index.aspx file:

require(["esri/config"], function(esriConfig) { 
 
 esriConfig.defaults.io.proxyUrl = "proxy.ashx"
    esriConfig.defaults.io.alwaysUseProxy = true;
 
 });


Proxy.ashx: Leave everything default.

Proxy.config file:

<ProxyConfig allowedReferers="*" mustMatch="true">
    <serverUrls>
        <serverUrl url="http://services.arcgisonline.com" matchAll="true"/>
  <serverUrl url="http://RemoteIP" matchAll="true"/>
  <serverUrl url="http://RemoteIP:6080" matchAll="true"/>
  
    </serverUrls>
</ProxyConfig>


These work fine when I do http://localhost/index.aspx

But, after copying the files the remote server and doing:
http://RemoteIP/index.aspx FireFox still shows the 'Cross Origin Request Block' error when accessing the url from my local workstation browser.

This is my first time with Proxies. What am I missing?

Thanks,
0 Kudos
IrfanClemson
Occasional Contributor II
Oh, wait--it is working now! Will confirm soon. Thanks.
0 Kudos
IrfanClemson
Occasional Contributor II
For the Record, I had only FireFox with this problem (IE and Chrome were fine) and using the Proxy per the ESRI link and per my posts above has indeed fixed the issue for FireFox.
@Koder303: Thanks!
0 Kudos