DotNET core is one of the most popular and powerful development frameworks. It is a large and well designed project but one common misunderstanding is the ways in which to configure an application using environment variables. Let us see the easier way to do so.
Store your settings in appsettings.json
First step is to define settings you wish to use in your projects file. Here is an example:
Here we have the standard logging and allowed host properties found in most apps. We also added a custom field called AppConfig. Within our custom property there are two nested fields. If we want to use secret or sensitive data in these fields it is best not to commit them to code by writing them into appsettings. Instead we should build our application and pass the secrets as environment variables to override the appsettings config properties.
Make sure you enable env
In your make sure to enable environment variables with the WebApplication builder config.
Setting environment variable overrides.
To replace values in your appsettings you must follow these rules:
- Prefix your env var with
- Use double underscore to separate nested fields
So to set the TwilioSecret in our AppConfig section we would run or build the application with the variable:
Recommended reading
Production config checklist for .NET email workflows
When appsettings and environment-variable overrides control email behavior, pair config changes with runtime validation.
- Provision deterministic inboxes in Email Sandbox.
- Validate end-to-end flows with Email Integration Testing.
- Capture async provider outcomes via Email Webhooks.
- Route retries and failure classes with Email Automation Routing.
- Verify inbox placement and sender health using Email Deliverability Test.



