Last active
January 8, 2019 09:12
-
-
Save GaProgMan/c4f1bd93036c12636a19d08817c40cce to your computer and use it in GitHub Desktop.
CORS example - .NET Core
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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