Skip to content

Instantly share code, notes, and snippets.

@sergeyt
Created October 16, 2013 15:19
Show Gist options
  • Save sergeyt/7009430 to your computer and use it in GitHub Desktop.
Save sergeyt/7009430 to your computer and use it in GitHub Desktop.
global.asax to enable CORS on IIS server
<%@ Application Language="C#" %>
<script runat="server">
void Application_BeginRequest(object sender, EventArgs e)
{
var context = HttpContext.Current;
var response = context.Response;
// enable CORS
response.AddHeader("Access-Control-Allow-Origin", "*");
response.AddHeader("X-Frame-Options", "ALLOW-FROM *");
if (context.Request.HttpMethod == "OPTIONS")
{
response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
response.AddHeader("Access-Control-Max-Age", "1728000");
response.End();
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment