Skip to content

Instantly share code, notes, and snippets.

@parrya
Created October 22, 2021 03:20
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 parrya/0b381781c9139f833dcc8d04cf0d51d5 to your computer and use it in GitHub Desktop.
Save parrya/0b381781c9139f833dcc8d04cf0d51d5 to your computer and use it in GitHub Desktop.
CORS header code for redirects in layout service
HttpResponseBase response = filterContext.HttpContext.Response;
response.Headers["Access-Control-Allow-Origin"] = header;
if (string.IsNullOrWhiteSpace(response.Headers.Get("Access-Control-Allow-Headers")))
response.AddHeader("Access-Control-Allow-Headers", "*");
if (string.IsNullOrWhiteSpace(response.Headers.Get("Access-Control-Allow-Credentials")))
response.AddHeader("Access-Control-Allow-Credentials", "true");
if (string.IsNullOrWhiteSpace(response.Headers.Get("Access-Control-Allow-Credentials")))
response.AddHeader("Access-Control-Expose-Headers", "ETag");
if (!string.IsNullOrWhiteSpace(response.Headers.Get("Access-Control-Max-Age")))
return;
response.AddHeader("Access-Control-Max-Age", "10");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment