Skip to content

Instantly share code, notes, and snippets.

@tonidy
Last active May 8, 2020 04:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonidy/c20af522e859dc887ef871cda4be9c35 to your computer and use it in GitHub Desktop.
Save tonidy/c20af522e859dc887ef871cda4be9c35 to your computer and use it in GitHub Desktop.
Global.asax.cs
//taken from https://blogs.msmvps.com/kenlin/2018/01/18/2694/
protected void Application_BeginRequest(object sender, EventArgs e)
{
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");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
HttpContext.Current.Response.AddHeader("Access-Control-Allow‌​-Credentials", "true");
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
HttpContext.Current.Response.End();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment