Config Section
The Config section controls how the configuration file itself is processed.
{
"Config": {
"ExposeAsEndpoint": null,
"AddEnvironmentVariables": false,
"ParseEnvironmentVariables": true,
"EnvFile": null
}
}Settings Reference
| Setting | Type | Default | Description |
|---|---|---|---|
ExposeAsEndpoint | string | null | Expose current configuration to an endpoint for debugging. Set to a path like "/config" to enable. Passwords in connection strings are not exposed. |
AddEnvironmentVariables | bool | false | Allow environment variables to override configuration settings. |
ParseEnvironmentVariables | bool | true | Parse {ENV_VAR_NAME} placeholders in config values and replace with environment variable values. |
EnvFile | string | null | Path to a .env file for loading environment variables. See below. |
Environment Variable Override
When AddEnvironmentVariables is true, environment variables can override any configuration setting. Use double underscores for nested keys:
# Override ConnectionStrings.Default
export ConnectionStrings__Default="Host=production-server;..."
# Override NpgsqlRest.UrlPathPrefix
export NpgsqlRest__UrlPathPrefix="/v2/api"Environment Variable Parsing
When ParseEnvironmentVariables is true (default), you can use {ENV_VAR} syntax anywhere in configuration values:
{
"ConnectionStrings": {
"Default": "Host={PGHOST};Port={PGPORT};Database={PGDATABASE};Username={PGUSER};Password={PGPASSWORD}"
}
}This allows sensitive values to be kept in environment variables rather than in the configuration file.
Loading from .env File
When AddEnvironmentVariables or ParseEnvironmentVariables is true and EnvFile is set, the application will load environment variables from the specified file:
{
"Config": {
"AddEnvironmentVariables": false,
"ParseEnvironmentVariables": true,
"EnvFile": ".env"
}
}The .env file format supports:
KEY=VALUEpairs (one per line)- Comments (lines starting with
#) - Quoted values (both single and double quotes)
Example .env file:
# Database connection settings
PGHOST=localhost
PGPORT=5432
PGDATABASE=example_db
PGUSER=postgres
PGPASSWORD=postgresThe variables are loaded into the environment and made available for configuration parsing with the {ENV_VAR_NAME} syntax.
Exposing Configuration
For debugging purposes, you can expose the current configuration as an endpoint:
{
"Config": {
"ExposeAsEndpoint": "/config"
}
}This creates a GET /config endpoint that returns the current configuration as JSON. Passwords in connection strings are automatically redacted.
Related
- Comment Annotations Guide - How annotations work
- Configuration Guide - How configuration sources work
Next Steps
- Connection Settings - Database connection strings
- Server & SSL - Kestrel and HTTPS configuration