liveBook · Manning

Appsettings.Development.json

As explained in Building Web APIs with ASP.NET Core

appsettings.Development.json is an ASP.NET Core environment-specific configuration file whose settings apply to the Development environment and override or extend shared settings.

appsettings.Development.json holds JSON configuration settings used only in the ASP.NET Core Development environment. It complements appsettings.json, which supplies shared settings for all environments. The development file is read after the shared file, so a matching key overrides the shared value. section 2.4.2

The runtime environment identifies the phase in which an app runs, such as Development, Staging, or Production. DOTNET_ENVIRONMENT or ASPNETCORE_ENVIRONMENT can select it; for local development, ASPNETCORE_ENVIRONMENT can be set in launchSettings.json. section 2.4.2

Enable the developer exception page locally

In the board-game API, set UseDeveloperExceptionPage to false in appsettings.json. Then add the same key with a value of true to appsettings.Development.json. The development value overrides the shared value only when the app runs in Development, keeping the potentially insecure page disabled by the shared setting elsewhere. section 2.4.2 section 2.4.3

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
"UseDeveloperExceptionPage": true
}

The development file adds UseDeveloperExceptionPage alongside its logging settings. section 2.4.3

if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}
 
if (app.Configuration.GetValue<bool>("UseDeveloperExceptionPage"))   #1
    app.UseDeveloperExceptionPage();                                 #2
else
    app.UseExceptionHandler("/error");                                #3

Program.cs reads the resulting Boolean setting to choose the developer exception page or the /error handler. The configuration value controls this choice; the file alone does not enable the middleware. section 2.4.3

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Explains environment selection and configuration precedence, then walks through adding an override and reading it in Program.cs.
Examples
Uses the board-game API’s UseDeveloperExceptionPage setting to override a shared false value with true in Development.
What you can do after
Operate/configure Development-specific settings and use a Boolean configuration value to select exception-handling middleware.
How it connects
Connects runtime environments, launchSettings.json, appsettings.json, configuration precedence, and exception-handling middleware.

Also explained in

Compare how 3 books explain appsettings.Development.json →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.