liveBook · Manning

Appsettings.json

As explained in Pro ASP.NET Core 7, Tenth Edition

appsettings.json is a conventional JSON file that stores application configuration settings for an ASP.NET Core application.

appsettings.json is the conventional JSON configuration file for an ASP.NET Core application. It stores settings such as logging levels, allowed hosts, and database connection strings, which the configuration service turns into hierarchical properties. section 7.2.2 section 15.2

Listing 7.15 Adding a configuration setting in the appsettings.json file in the SportsStore folder
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "SportsStoreConnection": "Server=(localdb)\\MSSQLLocalDB;Database=
SportsStore;MultipleActiveResultSets=true"
  }
}

Use the complete configuration listing to see the expected JSON structure, including nested logging settings and a ConnectionStrings entry. section 7.2.2

Configure appsettings.json with these practical constraints:

  • Place connection strings under ConnectionStrings and give each one a distinct name, such as SportsStoreConnection, PeopleConnection, or IdentityConnection. section 7.2.2 section 38.2.1
  • Keep each connection-string value on one unbroken line; the wrapped listings reflect page width rather than valid formatting. section 11.1.3
  • Treat JSON syntax strictly: quote property names and values exactly, and use the connection-string format required by the database server. section 7.2.2
  • Read settings through the configuration service, which merges appsettings.json with sources such as environment variables and command-line arguments. section 15.2

Environment-specific overrides

During startup, ASP.NET Core supplements appsettings.json with appsettings.Development.json when the environment is Development. Matching settings from the environment file replace the base values; for example, development logging can change Default from Information to Debug. section 15.2.1

The same pattern configures Entity Framework Core and ASP.NET Core Identity: define named database connections in JSON, then consume those names from application setup. section 32.2.2 section 38.2.1

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Explains JSON structure, hierarchical processing, source merging, and environment overrides, but defers detailed configuration usage to consuming services.
Examples
Uses LocalDB connection strings for SportsStore, People, and Identity databases alongside logging and AllowedHosts settings.
What it assumes
Assumes an ASP.NET Core application and basic JSON familiarity while teaching configuration sections and setting hierarchies.
What you can do after
Operate/configure ASP.NET Core applications with named connection strings and environment-specific logging settings.
How it connects
Connects configuration service with environment variables, command-line arguments, logging, Entity Framework Core, and ASP.NET Core Identity.

Also explained in

Compare how 4 books explain appsettings.json →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.