Skip to content

Instantly share code, notes, and snippets.

@ivanbuzyka
Forked from sergeyt/cors.global.asax
Created August 17, 2016 16:58
Show Gist options
  • Save ivanbuzyka/07d88ba4bb7ac3194a2a4d62d23bbe09 to your computer and use it in GitHub Desktop.
Save ivanbuzyka/07d88ba4bb7ac3194a2a4d62d23bbe09 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