appsettings.json stores an ASP.NET Core app’s shared configuration as JSON key-value pairs. In a web API project, it provides defaults for every runtime environment. A file such as appsettings.Development.json can add settings or override matching keys when the app runs in Development. section 2.4.2
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"UseDeveloperExceptionPage": false
}
The JSON listing shows grouped logging settings alongside a boolean UseDeveloperExceptionPage setting set to false. section 2.4.2
To configure behavior by environment:
- Set shared defaults in appsettings.json, then put Development-only overrides in appsettings.Development.json. The environment-specific file is read afterward, so its matching values take precedence. section 2.4.2
- Add a staging configuration file when Staging needs different values. For example, keep UseDeveloperExceptionPage false while setting UseSwagger true; these settings do not change behavior until the app uses them. section 2.5.2
Switch the error response
Program.cs can read app.Configuration.GetValue<bool>("UseDeveloperExceptionPage") to choose between DeveloperExceptionPageMiddleware and an exception handler. With the shared value set to false, start the app and visit /error/test: the thrown test exception produces a ProblemDetail JSON response. Put true in the Development-specific file when developers need the detailed exception page, rather than enabling it for every environment. section 2.4.3 section 2.5.2



