1

I have a GP service that generates a PDF report in reportlab based on a country clicked on a web map. I've placed the HTML/Javascript document on our web server for testing, and it's working (although we can only generate one report at a time, but that is a separate issue). I've tried to place this code in an HTML widget on our website and test it, and I keep getting the "XMLHttpRequest cannot load No 'Access-Control-Allow-Origin' header is present on the requested resource." I've tried to follow every thread I've found on this (there are dozens) and added "add name="Access-Control-Allow-Origin" value="*" to the web config files on our proxy server and the arcgis web config in the wwwroot. I'm still getting this error when I run the tool. We have two other pages on our website that use a GP tool to generate charts and these pages do not throw up this error. I'm not sure how to get this working.

2

Try to add this to the config:

<add name="Access-Control-Allow-Origin" value="*" />  
<add name="Access-Control-Allow-Headers" value="*" />  
<add name="Access-Control-Allow-Methods" value="*" />  
  • Thanks. Which config file? The one in the wwwroot folder? – Bill Hambone Mar 15 '17 at 19:09
  • web.config file – dmh126 Mar 15 '17 at 19:27
  • Right, there are two web config files, one on our proxy server and one in the wwwroot folder. – Bill Hambone Mar 15 '17 at 20:01
  • Actually there are three web config files in our wwwroot folder. Two for DotNet and one for the Arcgis web adapter. I still can't get it to work. – Bill Hambone Mar 16 '17 at 14:57
0

Just found this public CORS solution. I dropped this into the JavaScript and it works.

 (function() {
var cors_api_host = 'cors-anywhere.herokuapp.com';
var cors_api_url = 'https://' + cors_api_host + '/';
var slice = [].slice;
var origin = window.location.protocol + '//' + window.location.host;
var open = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function() {
var args = slice.call(arguments);
var targetOrigin = /^https?:\/\/([^\/]+)/i.exec(args[1]);
if (targetOrigin && targetOrigin[0].toLowerCase() !== origin &&
targetOrigin[1] !== cors_api_host) {
args[1] = cors_api_url + args[1];
}
return open.apply(this, args);
};
})();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.