Skip to content

Instantly share code, notes, and snippets.

@PradeepLoganathan
Last active June 29, 2020 23:30
Show Gist options
  • Select an option

  • Save PradeepLoganathan/2c6d08441d91d392e446ddaf762eea3b to your computer and use it in GitHub Desktop.

Select an option

Save PradeepLoganathan/2c6d08441d91d392e446ddaf762eea3b to your computer and use it in GitHub Desktop.
Defining and adding multiple CORS policies to the middleware
readonly string CORSPolicies.PublicAPI = "corspolicy.public";
readonly string CORSPolicies.DevAPI = "corspolicy.dev";
services.AddCors(options =>
{
options.AddPolicy(CORSPolicies.PublicAPI,
builder => builder
.AllowAnyHeader()
.WithMethods("POST", "GET")
.WithOrigins("https://domain1.com", "https://domain2.com"));
options.AddPolicy(CORSPolicies.DevAPI,
builder => builder
.AllowAnyHeader()
.AllowAnyMethod()
.AllowAnyOrigin());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment