I’m getting the error:
XMLHttpRequest cannot load http://www.scirra.com/handlers/arcadeProcessScore.ashx. Origin http://static1.scirra.net is not allowed by Access-Control-Allow-Origin.
On arcadeProcessScore.ashx I have the lines:
public void ProcessRequest (HttpContext context) {
context.Response.AppendHeader("Access-Control-Allow-Origin", "http://static1.scirra.net");
context.Response.AppendHeader("Access-Control-Allow-Origin", "https://static1.scirra.net");
context.Response.ContentType = "text/plain";
Yet the error still persists.
I’ve also tried simply:
context.Response.AppendHeader("Access-Control-Allow-Origin", "*");
Which doesn’t work either.
If I add <add name="Access-Control-Allow-Origin" value="*"/> at the web.config level it works, but obviously isn’t the solution.
How can I let arcadeProcessScore.ashx accept requests from static1.scirra.net? Thanks for any help.
I did some testing of my own, directly using an
XmlHttpRequestto access a handler in my project. The setup I used was to publish the application on my local IIS (which is version 6.1, so there might be differences in behaviour to 7.5) and to have theDefault.aspxpage call my handler running in the development server in Visual Studio. Like this:Code in the handler:
Using IE9, the behviour was the same regardless of whether or not I sent an
Access-Control-Allow-Originheader back from the handler. IE9 gives warning, asking the user to confirm if the content should be loaded.Both Chrome (version 21.0.1180.79 m) and FF (version 14.0.1) actually generates requests to the handler and respects the header that the handler sends back.
So this worked with Chrome and FF:
So did this:
But I have not been able to get either of them to show the content if I try to add several different allowed origins in the same response. For me, none of these worked:
Add several response headers
Add one header, two origins comma separated
Add one header, two origins space separated
Add one header, two origins space separated
To get it to work, what I did was to follow the advice given in this answer. My handler then looks like this:
With this, both Chrome and FF accept the output from the handler from both origins.