Store connection string outside version control

477 Views Asked by At

How do you go about database connection string handling in version control? As I understand, connection strings are usually held in appsettings.json, does that mean the best practice would be to add appsettings.json to .gitignore? I also have API keys, so would it be sensible to create a .env and add connection strings and API keys there?

1

There are 1 best solutions below

0
Xinran Shen On

When you use Visual Studio, You can right click the solution Name and select Manage User Secrets.

enter image description here

It will generate a secrets.json file, You can configure your connection string here and read it as in appsettings.json. This file is in the specified path Microsoft\UserSecrets\<user_secrets_id>\secrets.json in you local, So When you upload your project to Github, This file will not be uploaded together.

If you use another IDE like Rider, You need install plugin to achieve this function.