CORS error - not the normal sort

2737
9
11-15-2013 05:32 AM
AdrianMarsden
Occasional Contributor III
Hi
This Cross Origin thingy, AKA CORS has been discussed many time, however I have read those threads and none covers exactly what I am seeing.

I am only seeing this issue when I make a request for a legend.  The error doesn't always happen.  At 3.5 it would happen a few times, 2 out of 10 start ups.  When it fails my TOC breaks.  So I was naughty and put a loop in to simply try again.  The users didn't notice.

Now, using 3.7 and IE8 I get this every time, and of course my loop goes on forever.

I get
XMLHttpRequest cannot load http://ARGISserver/arcgis/rest/services/LIVEinternal/aerials/MapServer/legend?f=json. The 'Access-Control-Allow-Origin' whitelists only 'http://appURL'. Origin 'http://appURL_dev' is not in the list, and is therefore not allowed access. (index):1
k {stack: "Error: Unable to load http://ARGISserver/arcgis/rest???ev/arcgis_js_api/library/3.7/3.7/init.js:3570:29)", message: "Unable to load http://ARGISserver/arcgis/rest/servic???nternal/aerials/MapServer/legend?f=json status: 0", response: Object, status: 0, responseText: ""???}




So, have I forgotten that I've set one domain onto a whitelist somewhere?  I can't recall doing so.  Or is it a IE policy stting I have no control over?
0 Kudos
9 Replies
amenahgeebril
New Contributor
I have the same error
did you find it out?
0 Kudos
AdrianMarsden
Occasional Contributor III
adding

  <system.webServer>   <httpProtocol>
     <customHeaders>
       <add name="Access-Control-Allow-Origin" value="*" />
     </customHeaders>
   </httpProtocol>
 </system.webServer>


to my web.config (using IIS7 )

Helped a lot - still get the odd issue, but that cleared my main one.
0 Kudos
AdrianMarsden
Occasional Contributor III
OK - the error is now a bit more limited - certainly to Chrome based browsers.

I now get only
I get
XMLHttpRequest cannot load http://my server name/arcgis/rest/info?f=json. The 'Access-Control-Allow-Origin' whitelists only 'http://myURL, *'. Origin 'http://myURL' is not in the list, and is therefore not allowed access.


The request to http://my server name/arcgis/rest/info?f=json seems to be how the API determines if the server supports CORS (see http://forums.arcgis.com/threads/71824-quot-NetworkError-404-Not-Found-http-tasks.arcgis.com-ArcGIS-...)

It may be a genuine Chrome bug - see

https://code.google.com/p/chromium/issues/detail?id=321517

B
ut it is causing issues here.

Cheers

ACM
0 Kudos
AdrianMarsden
Occasional Contributor III

bump - still getting this - anyone any ideas how to make it stop?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Adrian,

   Have you considered just turning cors detection off? esri.config.defaults.io.corsDetection = false;

AdrianMarsden
Occasional Contributor III

Not sure I know where to put that.  However, I replaced the * in the

http://server/arcgis/admin/system/handlers/rest/servicesdirectory

With some random text and that sorted it.  I think too many things were trying to do the same thing - I have really no idea what I am talking about.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Adrain,

   That line would just go in your code before to initiate your map var

AdrianMarsden
Occasional Contributor III

Brill - that worked as well - much better than playing with options I had no idea about, many thanks

0 Kudos
PaulCrickard1
Occasional Contributor II

Using Server Manager, in IIS, you can navigate to the site and under the HTTP Response Headers you can choose ADD, then title Access-Control-Allow-Origin and value is the IP or domain of the site you want to allow. Could always choose * for everyone.

While you can do it in your code, Server side is probably the best option.