// Adding CORS
var corsPolicyOptions = builder.Configuration.GetSection("CorsPolicy");
builder.Services.AddCorsPolicy(corsPolicyOptions);
// Adding HSTS
var hstsOptions = builder.Configuration.GetSection("Hsts");
builder.Services.AddHttpsPolicy(hstsOptions);
// Using CORS middleware
app.UseCorsPolicy(corsPolicyOptions);
// Using HSTS middleware
app.UseHstsOnProduction(builder.Environment);
Added getting CORS and HSTS options from JSON configuration files.
How to use?
cors.json:
hsts.json:
Program.cs: