the end of 2019 and still battling CORS issues

2117
4
11-13-2019 03:35 AM
AdrianMarsden
Regular Contributor II

This is the error that never goes away and drives me nuts

The site is using the latest 3.x api

It does NOT use the proxy.aspx page

the server is , lets say "esri-gis1"

there is an internal site in the internal DSN, let's call that "maps"

users access the site by using "maps" as a URL

The code calls maps from esri-gis1\arcgis\rest\services......

The map page works fine.  Requests are fine and if I examine the response headers for the basic requests it shows * in the Allow-Control-Allow-Origin


The issues start when I call, for example I call the geometry service

http://esri-gis1/arcgis/rest/services/Utilities/Geometry/GeometryServer 

In a task that I use to convert the local grid to Long Lat

Then I get the 

Access to XMLHttpRequest at 'http://esri-gis1/arcgis/rest/services/Utilities/Geometry/GeometryServer/project?.........' from origin 'http://maps' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I got around this on the current site by using the Proxy page and adding

            esri.config.defaults.io.corsEnabledServers.push("esri-gis1");

But I ind the Proxy page adds more trouble than it solves.

Any help please?

ACM

0 Kudos
4 Replies
AdrianMarsden
Regular Contributor II

..and adding stuff to the AGS webconfig to enable * then gives errors that I have added too much in different places -

Access to XMLHttpRequest at 'http://esri-gis1/server/rest/info?f=json' from origin 'http://maps' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains multiple values 'http://maps, *', but only one is allowed.

0 Kudos
AdrianMarsden
Regular Contributor II

Doh! For some reason the geometry and other URLs are now different from my original code - and I should have been getting 404, rather than this COR error

I had 

http://esri-gis1/arcgis/rest/services/Utilities/Geometry/GeometryServer 

But it is now

http://esri-gis1/server/rest/services/Utilities/Geometry/GeometryServer 

That extra word "server" has crept in

0 Kudos
JordanKing3
New Contributor III

Hey Adrian Marsden,

Could you clarify a few more things here:

1. is your JavaScript application running on IIS and running on the server which has a DNS Alias as 'maps'?

2. this server 'maps', is different to 'esri-gis'?

3. you mentioned that your URL changed from arcgis/rest/services to server/rest/services, does this mean someone has now configured an ArcGIS Web Adaptor called 'server' on the 'esri-gis' server and connected it with your ArcGIS Server on that machine?

By default, I think every ArcGIS Server deployment has CORS enabled and the response set to *, so you shouldn't need to be manually changing the underlying ArcGIS Server config.

0 Kudos
AdrianMarsden
Regular Contributor II

OK - I think this is all sorted - I don't know how/where but my code on the old server had

http://esri-gis1-oldserver/arcgis/rest/services/Utilities/Geometry/GeometryServer

Where as the new server has

http://esri-gis1-NEW-server/server/rest/services/Utilities/Geometry/GeometryServer 

I would have expected that this would have caused a 404 error and I would have noticed straight away.

But instead I got the CORS error, so spent ages looking at that, rather than the real, and a lot simpler issue, of a bad URL

Odd, but I'm moving on now :)

Thanks for the help

0 Kudos