If you want to set the CORS settings in appsettings.json and use the settings in startup.cs, you can follow the code below:
This is my appsettings.json:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"AllowedOrigins": "http://localhost:4200",
"AllowedHeaders": "content-type",
"AllowedMethods": "GET,POST,PUT,DELETE"
}
This is my partial code in startup.cs:
app.UseCors(x => x.WithOrigins(Configuration.GetSection("AllowedOrigins").Value.Split(","))
.AllowCredentials().WithHeaders(Configuration.GetSection("AllowedHeaders").Value.Split(","))
.WithMethods(Configuration.GetSection("AllowedMethods").Value.Split(",")));
app.UseHttpsRedirection();