Tuesday, November 20, 2018

Keeping Secrets out of the web.config

See here for Microsofts official recommendations on best practices to keep secrets out of the web config.

I am mostly concerned about appSettings and connectionStrings sections in the web.config

The Microsoft article says everything I am going to say below, but they are some important points to consider.

appSettings

To keep your appSettings secret, put them in another file that is not checked into source control. The contents of this file will be merged with what is in the web.config so this works well to allow developers to override values in appSettings.

The syntax is basically

<appSettings file="..\..\AppSettingsSecrets.config"> <add key="webpages:Version" value="3.0.0.0" /> <add key="webpages:Enabled" value="false" /> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> </appSettings>

The file attribute accepts paths that are relative or absolve and the file does not have to exist. This is useful when deploying to different environments that may not use this file and instead use VSTS / replacing of tokens to manage values per environment.


connectionStrings

The connectionStrings section isn't as nice as the appSettings. The tags between connectionString tags are replaced by the contents of the external file. The file referenced MUST be in the same directory as the web.config that is referencing it. This means the secret file is per project. The other thing that makes it not work as easily is that it MUST exist otherwise you will get a build error because the project file will try to find the file. You can edit the project file and tell it to only include the file in the project for particular environments, but that is tedious and must be done on each project file.


4 comments:

Leo Oscar said...

Thank you so much for this useful information. looking more from your side to update us on more updates and advancements

Blog27999 said...

Do this hack to drop 2 lbs of fat in 8 hours

Over 160k women and men are trying a simple and secret "water hack" to lose 2 lbs each and every night in their sleep.

It's effective and it works every time.

Here's how you can do it yourself:

1) Go get a glass and fill it half glass

2) And now use this weight loss HACK

you'll be 2 lbs lighter as soon as tomorrow!

DevOps Online Training said...

Thanks for sharing...
Leanpitch provides online training in DevOps during this lockdown period everyone can use it wisely.
DevOps Online Training

Scrum Master said...

Thanks for sharing this...
Leanpitch provides online training in Scrum during this lockdown period everyone can use it wisely.
Scrum Values