Skip to content

Instantly share code, notes, and snippets.

@awswithdotnet
Created March 8, 2022 15:54
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 awswithdotnet/cc4297b10a03a1f9d08963d21531e925 to your computer and use it in GitHub Desktop.
Save awswithdotnet/cc4297b10a03a1f9d08963d21531e925 to your computer and use it in GitHub Desktop.
cors Startup ConfigureService Complete
public static void ConfigureService(IServiceCollection services, IConfiguration configuration)
{
services.AddCors(options =>
{
options.AddPolicy("AllowAnyOrigin",
builder => builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
options.AddPolicy("AllowSpecificOrigins",
builder =>
{
List<CorsOrigin> origins = new List<CorsOrigin>();
configuration.GetSection("cors:origins").Bind(origins);
foreach (var o in origins)
{
builder.WithOrigins(o.Uri);
}
builder
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials();
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment