Fighting CORS. I have a site that makes a simple XmlHttpRequest for the web API that I built in C #.
var xhr = new XMLHttpRequest();
xhr.open("GET","https://server/controller/method", true);
xhr.send();
In my web.config, I did the following:
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
I also tried installing the Nuget package and doing the following in my WebApiConfig.cs
var cors = new EnableCorsAttribute(
origins: "*",
headers: "*",
methods: "*");
config.EnableCors(cors);
Despite these efforts, CORS is still not working. In the Firefox console, I get the following error:
Cross-request blocking: the same origin policy prohibits reading the remote resource on the https: // server . This can be fixed by moving the resource to the same domain or by enabling CORS.
IE also just crashes and does not throw errors.
, , , . - / JavaScript? CORS , Visual Studio IIS Express localhost: PortNumber? ?