Skip to content

Instantly share code, notes, and snippets.

@johndaley-me
Created June 25, 2015 15:55
Show Gist options
  • Save johndaley-me/b933ad286f91bb044e21 to your computer and use it in GitHub Desktop.
Save johndaley-me/b933ad286f91bb044e21 to your computer and use it in GitHub Desktop.
CORS for Web API < 2
#if DEBUG
protected void Application_BeginRequest(object sender, System.EventArgs e)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
// These headers are handling the "pre-flight" OPTIONS call sent by the browser
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
// Match these to those in the request
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, Authorization");
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
HttpContext.Current.Response.End();
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment