Skip to content

Instantly share code, notes, and snippets.

@GaProgMan GaProgMan/startup.cs
Last active Jan 8, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.