<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic CORS issues driving you bonkers? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cors-issues-driving-you-bonkers/m-p/315584#M29008</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don’t know about you, but I’m a developer by accident: My job title says nothing about coding in JavaScript or being able to troubleshoot authentication or security issues or, most importantly those pesky CORS issues – but I’ve had quite an intensive relationship with “Cross-origin request sharing” issues, so the technical term, recently.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you have NOT seen them before (and I doubt that you’re so lucky, because you’ve found this post after all…) – the symptom often appears in a browser when you try to load your web application and manifests by – superficially – the browser not seeming to load a resource. (Worst case it won’t load anything at all and also not give you an error message – so you’ll need to open the Console as part of the Developer Tools in the browser to confirm).&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="483326" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/483326_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;P&gt;The whole thing is meant to make it more secure for a user to use a web browser without pulling stuff from random sources together, as far as I understand. (Mozilla &lt;A class="link-titled" href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS" title="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS"&gt;Cross-Origin Resource Sharing (CORS) - HTTP | MDN&lt;/A&gt;&amp;nbsp;)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The error can pop up in a variety of configurations, be that a custom Web App Builder (Dev Edition) app that you deploy using services from ArcGIS Enterprise and/or ArcGIS Online or a custom app made using the JavaScript API.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After tearing a few handful of my - now grey - hair out and biting larg-ish chunks out of my desk, I also went to Geonet and found a few reassuring hints that confirmed that I wasn’t alone - like &lt;A _jive_internal="true" href="https://community.esri.com/thread/231006-cors-is-not-allowing-wab-to-connect-to-my-agol-org?q=cors"&gt;https://community.esri.com/message/840788-cors-is-not-allowing-wab-to-connect-to-my-agol-org?q=cors&lt;/A&gt; (a.k.a. don’t whitelist pages – if they haven’t been blacklisted)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Of course, I’ve consulted the &lt;STRONG&gt;Esri documentation&lt;/STRONG&gt;, principally the developer site, a few examples being:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.esri.com/arcgis-blog/products/js-api-arcgis/mapping/cross-origin-resource-sharing-cors-with-the-arcgis-api-for-javascript/"&gt;https://www.esri.com/arcgis-blog/products/js-api-arcgis/mapping/cross-origin-resource-sharing-cors-with-the-arcgis-api-for-javascript/&lt;/A&gt; (from &lt;STRONG&gt;2011&lt;/STRONG&gt; – so this is be no means a new thing – and t&lt;STRONG&gt;his document should perhaps no longer appear in Google searches&lt;/STRONG&gt; as it refers to outdated solutions/workarounds which may make things worse and don't apply to v4 API etc.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/guide/cors/"&gt;https://developers.arcgis.com/javascript/latest/guide/cors/&lt;/A&gt; (for the brand-new JS API, 4.11 at the time of writing). This document states at the beginning&lt;EM&gt; “When both the web server and the browser support CORS, a &lt;A href="https://en.wikipedia.org/wiki/Proxy_server"&gt;proxy&lt;/A&gt; is not required to do cross-domain requests” – &lt;/EM&gt;so I was delighted, because I wasn’t sure how to use the proxy setup, which is rather thinly described here &lt;A href="https://developers.arcgis.com/javascript/latest/guide/proxies/"&gt;https://developers.arcgis.com/javascript/latest/guide/proxies/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;And the above Esri 4.11 documentation, of course, still refers to &lt;A href="https://enable-cors.org/server_iis7.html"&gt;https://enable-cors.org/server_iis7.html&lt;/A&gt; which (only) has links to IIS6 and IIS7. Hang on – IIS7, that was part of Window Vista and Windows Server 2008! We have Windows servers for all of our GIS, so what about my Windows 2016 server with IIS10, or even the Windows 2019 servers – does the same still apply? Looks as if I’ll just have to assume that it does for lack of a better source of information … so off I went I tried to comply:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Enable-cors.org&lt;/STRONG&gt; states that for CORS on IIS7 you need to &lt;EM&gt;“Merge this into the web.config file at the root of your application or site”&lt;/EM&gt; and gives you a bit of XML to insert.&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="483327" class="image-2 jive-image" src="https://community.esri.com/legacyfs/online/483327_pastedImage_5.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I wasn’t quite sure where I would add it and, using trial and error, several IIS service restarts later, I seemed to have some successes: several times I was able to load a layer which it previously had refused to load. &lt;STRONG&gt;Then, other times, in other applications it would suddenly refuse to load them ( the error message had changed now and was saying something along the lines of “Access-Control-Allow-&lt;EM&gt;Credentials&lt;/EM&gt; request not permitted when the rule is &lt;EM&gt;"Access-Control-Allow-Origin" value="*" &lt;/EM&gt;or so.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hm, yes, that’s the rule in the XML from enable-cors that I’ve added to the Web.config at the root of my IIS site. So why is it not working in this case?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Turns out that, apparently, while the above rule (XML) from &lt;EM&gt;enable-cors.org&lt;/EM&gt; opens up the web server to allow all sorts of Cross-Origin-Requests being made, &lt;STRONG&gt;current browsers consider that to be too insecure to accept and refuse to load some secured layers&lt;/STRONG&gt; (which are kind of requested using credentials, I believe). So we’ll need to be more specific and set up rules on the Web Server which allow making requests from a variety of sources that are getting mashed up in our application.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Okay, so let me try a proxy configuration (the Esri documentation says “Before &lt;A href="https://developers.arcgis.com/javascript/latest/guide/cors/index.html"&gt;CORS&lt;/A&gt;, it was necessary to work with a &lt;A href="https://en.wikipedia.org/wiki/Proxy_server"&gt;proxy&lt;/A&gt; page. This was helpful as it was used to bypass the issue many applications had when accessing resources that were not on the same origin.”)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The idea is that I’ll simply get the dotNet (ASP.NET) config from Esri’s GitHub &amp;nbsp;&lt;A href="https://github.com/Esri/resource-proxy/tree/master/DotNet"&gt;https://github.com/Esri/resource-proxy/tree/master/DotNet&lt;/A&gt; &amp;nbsp;&amp;nbsp;– perhaps that’s easier?!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes. No. Kind of. I was able to specify some rules for some of the services and actually that eventually let me load my application with all it’s mashed-up services from different origins alright. But there are some intricacies: Because the Proxy acts as the middle-man between your application and the services that your application tries to load, there is a communication overhead – which slows things down (a bit). If you’ve got large numbers of features, for instance, that you’re trying to show on the screen, perhaps using the new feature binning, then the fact that all traffic has to be facilitated by the proxy page on your web server, will potentially slow down your application considerably (my application was very, very slow when using the proxy page). I also had just started to deploy my applications using &lt;STRONG&gt;netlify&lt;/STRONG&gt; and &lt;STRONG&gt;github &lt;/STRONG&gt;and didn't like the thought that some of our AppIDs might slip into a public repository along with a proxy page (that also netflify can't even use!)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;So don't use a proxy page - unless you have to. &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Back to the square one… &amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Let’s continue our effort to google this. Here’s an interesting Blog Post from Esri’s Julie Powell, perhaps that’s got some new ideas: &lt;A _jive_internal="true" href="https://community.esri.com/community/developers/web-developers/arcgis-api-for-javascript/blog/2018/08/30/cors-and-the-arcgis-api-for-javascript-changes-coming-in-49"&gt;https://community.esri.com/community/developers/web-developers/arcgis-api-for-javascript/blog/2018/08/30/cors-and-the-arcgis-api-for-javascript-changes-coming-in-49&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you scroll down a bit the post says this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;H3&gt;“Changes to how the API will handle CORS, starting at 4.9&lt;/H3&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;The API will &lt;EM&gt;assume&lt;/EM&gt; web servers support CORS. Here are the details behind how the API handled CORS until 4.8, and how it will change starting at 4.9.&lt;/SPAN&gt;&lt;STRONG&gt;”&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And here’s the crux: the API will &lt;STRONG&gt;assume&lt;/STRONG&gt; that your web server supports CORS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Well our IIS servers, in their default configuration, certainly &lt;STRONG&gt;didn’t&lt;/STRONG&gt; support CORS. Why? Because it’s not the default when you install it (and no-one knew any better at the time of installation so nothing else was done to enable it, so it would become the new default.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;STRONG&gt;Never assume!&lt;/STRONG&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt; as a project manager once said to me.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And here’s the solution: there’s a module for IIS from Microsoft which can be installed and configured in a fine-grained way.&lt;/P&gt;&lt;P&gt;Here’s some documentation from Microsoft &lt;A href="https://docs.microsoft.com/en-us/iis/extensions/cors-module/cors-module-configuration-reference#cors-configuration"&gt;https://docs.microsoft.com/en-us/iis/extensions/cors-module/cors-module-configuration-reference#cors-configuration&lt;/A&gt; and here’s where to download the module &lt;A href="https://www.iis.net/downloads/microsoft/iis-cors-module"&gt;https://www.iis.net/downloads/microsoft/iis-cors-module&lt;/A&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;configuration&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;system.webServer&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cors enabled="true" failUnlistedOrigins="true"&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add origin="*" /&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add origin="https://*.microsoft.com"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; allowCredentials="true"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; maxAge="120"&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;allowHeaders allowAllRequestedHeaders="true"&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add header="header1" /&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add header="header2" /&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/allowHeaders&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;allowMethods&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;add method="DELETE" /&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/allowMethods&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;exposeHeaders&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add header="header1" /&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add header="header2" /&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/exposeHeaders&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/add&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add origin="http://*" allowed="false" /&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/cors&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/system.webServer&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;/configuration&amp;gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Summarising:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CORS issues will be a steady companion if you do any development using services from multiple sources (and you most likely will). They’re relatively easy to get rid of with the above module (if, like we do, you use IIS on Windows) but it will need to be configured – almost always, as I venture to assume…&lt;/P&gt;&lt;P&gt;Make sure you revert all your efforts in various bits of application web.config files (e.g. from Web App Builder) once you’ve got your configuration ready in the IIS CORS Module configuration.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PS: In case you use netlify, use a netlify.toml file to define your rules - i've had some good success with that too (but it's similarly loose in the example below and you'll find that with some secured services from, say an Enterprise portal, it won't allow those services to be loaded).&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="483328" class="image-3 jive-image" src="https://community.esri.com/legacyfs/online/483328_pastedImage_13.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 26 Feb 2020 04:25:50 GMT</pubDate>
    <dc:creator>TilmannSteinmetz2</dc:creator>
    <dc:date>2020-02-26T04:25:50Z</dc:date>
    <item>
      <title>CORS issues driving you bonkers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cors-issues-driving-you-bonkers/m-p/315584#M29008</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don’t know about you, but I’m a developer by accident: My job title says nothing about coding in JavaScript or being able to troubleshoot authentication or security issues or, most importantly those pesky CORS issues – but I’ve had quite an intensive relationship with “Cross-origin request sharing” issues, so the technical term, recently.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you have NOT seen them before (and I doubt that you’re so lucky, because you’ve found this post after all…) – the symptom often appears in a browser when you try to load your web application and manifests by – superficially – the browser not seeming to load a resource. (Worst case it won’t load anything at all and also not give you an error message – so you’ll need to open the Console as part of the Developer Tools in the browser to confirm).&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="483326" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/483326_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;P&gt;The whole thing is meant to make it more secure for a user to use a web browser without pulling stuff from random sources together, as far as I understand. (Mozilla &lt;A class="link-titled" href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS" title="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS"&gt;Cross-Origin Resource Sharing (CORS) - HTTP | MDN&lt;/A&gt;&amp;nbsp;)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The error can pop up in a variety of configurations, be that a custom Web App Builder (Dev Edition) app that you deploy using services from ArcGIS Enterprise and/or ArcGIS Online or a custom app made using the JavaScript API.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After tearing a few handful of my - now grey - hair out and biting larg-ish chunks out of my desk, I also went to Geonet and found a few reassuring hints that confirmed that I wasn’t alone - like &lt;A _jive_internal="true" href="https://community.esri.com/thread/231006-cors-is-not-allowing-wab-to-connect-to-my-agol-org?q=cors"&gt;https://community.esri.com/message/840788-cors-is-not-allowing-wab-to-connect-to-my-agol-org?q=cors&lt;/A&gt; (a.k.a. don’t whitelist pages – if they haven’t been blacklisted)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Of course, I’ve consulted the &lt;STRONG&gt;Esri documentation&lt;/STRONG&gt;, principally the developer site, a few examples being:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.esri.com/arcgis-blog/products/js-api-arcgis/mapping/cross-origin-resource-sharing-cors-with-the-arcgis-api-for-javascript/"&gt;https://www.esri.com/arcgis-blog/products/js-api-arcgis/mapping/cross-origin-resource-sharing-cors-with-the-arcgis-api-for-javascript/&lt;/A&gt; (from &lt;STRONG&gt;2011&lt;/STRONG&gt; – so this is be no means a new thing – and t&lt;STRONG&gt;his document should perhaps no longer appear in Google searches&lt;/STRONG&gt; as it refers to outdated solutions/workarounds which may make things worse and don't apply to v4 API etc.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/guide/cors/"&gt;https://developers.arcgis.com/javascript/latest/guide/cors/&lt;/A&gt; (for the brand-new JS API, 4.11 at the time of writing). This document states at the beginning&lt;EM&gt; “When both the web server and the browser support CORS, a &lt;A href="https://en.wikipedia.org/wiki/Proxy_server"&gt;proxy&lt;/A&gt; is not required to do cross-domain requests” – &lt;/EM&gt;so I was delighted, because I wasn’t sure how to use the proxy setup, which is rather thinly described here &lt;A href="https://developers.arcgis.com/javascript/latest/guide/proxies/"&gt;https://developers.arcgis.com/javascript/latest/guide/proxies/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;And the above Esri 4.11 documentation, of course, still refers to &lt;A href="https://enable-cors.org/server_iis7.html"&gt;https://enable-cors.org/server_iis7.html&lt;/A&gt; which (only) has links to IIS6 and IIS7. Hang on – IIS7, that was part of Window Vista and Windows Server 2008! We have Windows servers for all of our GIS, so what about my Windows 2016 server with IIS10, or even the Windows 2019 servers – does the same still apply? Looks as if I’ll just have to assume that it does for lack of a better source of information … so off I went I tried to comply:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Enable-cors.org&lt;/STRONG&gt; states that for CORS on IIS7 you need to &lt;EM&gt;“Merge this into the web.config file at the root of your application or site”&lt;/EM&gt; and gives you a bit of XML to insert.&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="483327" class="image-2 jive-image" src="https://community.esri.com/legacyfs/online/483327_pastedImage_5.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I wasn’t quite sure where I would add it and, using trial and error, several IIS service restarts later, I seemed to have some successes: several times I was able to load a layer which it previously had refused to load. &lt;STRONG&gt;Then, other times, in other applications it would suddenly refuse to load them ( the error message had changed now and was saying something along the lines of “Access-Control-Allow-&lt;EM&gt;Credentials&lt;/EM&gt; request not permitted when the rule is &lt;EM&gt;"Access-Control-Allow-Origin" value="*" &lt;/EM&gt;or so.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hm, yes, that’s the rule in the XML from enable-cors that I’ve added to the Web.config at the root of my IIS site. So why is it not working in this case?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Turns out that, apparently, while the above rule (XML) from &lt;EM&gt;enable-cors.org&lt;/EM&gt; opens up the web server to allow all sorts of Cross-Origin-Requests being made, &lt;STRONG&gt;current browsers consider that to be too insecure to accept and refuse to load some secured layers&lt;/STRONG&gt; (which are kind of requested using credentials, I believe). So we’ll need to be more specific and set up rules on the Web Server which allow making requests from a variety of sources that are getting mashed up in our application.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Okay, so let me try a proxy configuration (the Esri documentation says “Before &lt;A href="https://developers.arcgis.com/javascript/latest/guide/cors/index.html"&gt;CORS&lt;/A&gt;, it was necessary to work with a &lt;A href="https://en.wikipedia.org/wiki/Proxy_server"&gt;proxy&lt;/A&gt; page. This was helpful as it was used to bypass the issue many applications had when accessing resources that were not on the same origin.”)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The idea is that I’ll simply get the dotNet (ASP.NET) config from Esri’s GitHub &amp;nbsp;&lt;A href="https://github.com/Esri/resource-proxy/tree/master/DotNet"&gt;https://github.com/Esri/resource-proxy/tree/master/DotNet&lt;/A&gt; &amp;nbsp;&amp;nbsp;– perhaps that’s easier?!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes. No. Kind of. I was able to specify some rules for some of the services and actually that eventually let me load my application with all it’s mashed-up services from different origins alright. But there are some intricacies: Because the Proxy acts as the middle-man between your application and the services that your application tries to load, there is a communication overhead – which slows things down (a bit). If you’ve got large numbers of features, for instance, that you’re trying to show on the screen, perhaps using the new feature binning, then the fact that all traffic has to be facilitated by the proxy page on your web server, will potentially slow down your application considerably (my application was very, very slow when using the proxy page). I also had just started to deploy my applications using &lt;STRONG&gt;netlify&lt;/STRONG&gt; and &lt;STRONG&gt;github &lt;/STRONG&gt;and didn't like the thought that some of our AppIDs might slip into a public repository along with a proxy page (that also netflify can't even use!)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;So don't use a proxy page - unless you have to. &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Back to the square one… &amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Let’s continue our effort to google this. Here’s an interesting Blog Post from Esri’s Julie Powell, perhaps that’s got some new ideas: &lt;A _jive_internal="true" href="https://community.esri.com/community/developers/web-developers/arcgis-api-for-javascript/blog/2018/08/30/cors-and-the-arcgis-api-for-javascript-changes-coming-in-49"&gt;https://community.esri.com/community/developers/web-developers/arcgis-api-for-javascript/blog/2018/08/30/cors-and-the-arcgis-api-for-javascript-changes-coming-in-49&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you scroll down a bit the post says this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;H3&gt;“Changes to how the API will handle CORS, starting at 4.9&lt;/H3&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;The API will &lt;EM&gt;assume&lt;/EM&gt; web servers support CORS. Here are the details behind how the API handled CORS until 4.8, and how it will change starting at 4.9.&lt;/SPAN&gt;&lt;STRONG&gt;”&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And here’s the crux: the API will &lt;STRONG&gt;assume&lt;/STRONG&gt; that your web server supports CORS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Well our IIS servers, in their default configuration, certainly &lt;STRONG&gt;didn’t&lt;/STRONG&gt; support CORS. Why? Because it’s not the default when you install it (and no-one knew any better at the time of installation so nothing else was done to enable it, so it would become the new default.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;STRONG&gt;Never assume!&lt;/STRONG&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt; as a project manager once said to me.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And here’s the solution: there’s a module for IIS from Microsoft which can be installed and configured in a fine-grained way.&lt;/P&gt;&lt;P&gt;Here’s some documentation from Microsoft &lt;A href="https://docs.microsoft.com/en-us/iis/extensions/cors-module/cors-module-configuration-reference#cors-configuration"&gt;https://docs.microsoft.com/en-us/iis/extensions/cors-module/cors-module-configuration-reference#cors-configuration&lt;/A&gt; and here’s where to download the module &lt;A href="https://www.iis.net/downloads/microsoft/iis-cors-module"&gt;https://www.iis.net/downloads/microsoft/iis-cors-module&lt;/A&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;configuration&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;system.webServer&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cors enabled="true" failUnlistedOrigins="true"&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add origin="*" /&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add origin="https://*.microsoft.com"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; allowCredentials="true"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; maxAge="120"&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;allowHeaders allowAllRequestedHeaders="true"&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add header="header1" /&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add header="header2" /&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/allowHeaders&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;allowMethods&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;add method="DELETE" /&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/allowMethods&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;exposeHeaders&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add header="header1" /&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add header="header2" /&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/exposeHeaders&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/add&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add origin="http://*" allowed="false" /&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/cors&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/system.webServer&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;/configuration&amp;gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Summarising:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CORS issues will be a steady companion if you do any development using services from multiple sources (and you most likely will). They’re relatively easy to get rid of with the above module (if, like we do, you use IIS on Windows) but it will need to be configured – almost always, as I venture to assume…&lt;/P&gt;&lt;P&gt;Make sure you revert all your efforts in various bits of application web.config files (e.g. from Web App Builder) once you’ve got your configuration ready in the IIS CORS Module configuration.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PS: In case you use netlify, use a netlify.toml file to define your rules - i've had some good success with that too (but it's similarly loose in the example below and you'll find that with some secured services from, say an Enterprise portal, it won't allow those services to be loaded).&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="483328" class="image-3 jive-image" src="https://community.esri.com/legacyfs/online/483328_pastedImage_13.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Feb 2020 04:25:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cors-issues-driving-you-bonkers/m-p/315584#M29008</guid>
      <dc:creator>TilmannSteinmetz2</dc:creator>
      <dc:date>2020-02-26T04:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: CORS issues driving you bonkers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cors-issues-driving-you-bonkers/m-p/1047205#M72535</link>
      <description>&lt;P&gt;so where does one put the config statement? in the portal config file or IIS root level?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 19:02:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cors-issues-driving-you-bonkers/m-p/1047205#M72535</guid>
      <dc:creator>LeoLadefian3</dc:creator>
      <dc:date>2021-04-14T19:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: CORS issues driving you bonkers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cors-issues-driving-you-bonkers/m-p/1271797#M80668</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/370421"&gt;@TilmannSteinmetz2&lt;/a&gt;&amp;nbsp;, thanks so much for this article.&lt;/P&gt;&lt;P&gt;I have been painfully trying to figure out our CORS errors for a Web Appbuilder extension being hosted in IIS. I have felt the same pain as in this article.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 04:50:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cors-issues-driving-you-bonkers/m-p/1271797#M80668</guid>
      <dc:creator>SSchott_CLAU</dc:creator>
      <dc:date>2023-03-27T04:50:40Z</dc:date>
    </item>
  </channel>
</rss>

