Videos
Check out our tutorial video series.
Effortlessly configure apps in DotNET Core with prefixed environment variables. Set and override appsettings.json values without code commits.
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.
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.
In your make sure to enable environment variables with the WebApplication builder config.
To replace values in your appsettings your must follow these rules:
So to set the TwilioSecret in our AppConfig section we would run or build the application with the variable:
Check out our tutorial video series.
Email and SMS guides for automation and testing.
View github project code for multiple languages.
Latest posts from the MailSlurp team.
Test, build, and automate messaging with a free MailSlurp account.