Skip to content

Instantly share code, notes, and snippets.

@GaProgMan
Last active January 8, 2019 09:12
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 GaProgMan/c4f1bd93036c12636a19d08817c40cce to your computer and use it in GitHub Desktop.
Save GaProgMan/c4f1bd93036c12636a19d08817c40cce to your computer and use it in GitHub Desktop.
CORS example - .NET Core
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy("nameOfPolicyHere", builder =>
{
builder.WithOrigins("array of strings", "representing origins");
// headers can be complext to start with, so I would start with
//builder.AllowAnyHeader();
// just to get it working first, then reduce the number of headers
// that you allow with something like the following
builder.WithHeders(HeaderNames.Referer);
// Similaraly with methods, it can be useful (fro dev sites) to
// start out allowing everything with the following:
// builder.AllowAnyMethod();
// Once you have it up and running, reduce the number of methods
// with something like
builder.WithMethods(HttpMethods.Get, HttpMethods.Post);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment