0

On my dev machine I store connection strings in all of my Appsettings{environment}.json files.
When I have some kind of problem in Production environment I change the launch.settings file to Production and then I can debug the solution using Production database.

I would like to move some credentials keys from my Appsettings files and store them in UserSecret on my dev machine.

From my understanding the UserSecret doesn't support UserSecret{environment}.json like appsettings does.
Does .Net Core support User Secrets per environment?

So how can I use UserSecret on my local machine but yet keep the ability to change the connection string when environment changes in LaunchSettings?

Offir
  • 3,252
  • 3
  • 41
  • 73

1 Answers1

2

As far as I know, the User Secrets are only for development and not intended for production. Production secrets shouldn't be used for development or test. Secrets shouldn't be deployed with the app.

You could could try to use multiple connection strings, like: ConnectionStrings:productionDB and ConnectionStrings:developmentDB.

Besides, production secrets should be accessed through a controlled means like environment variables or Azure Key Vault. You can store and protect Azure test and production secrets with the Azure Key Vault configuration provider.

More detail information, you could refer the following articles:

Safe storage of app secrets in development in ASP.NET Core

Use multiple environments in ASP.NET Core

Storing production secrets in ASP.NET Core

Zhi Lv
  • 18,845
  • 1
  • 19
  • 30
  • `ConnectionStrings:productionDB` this approach is not supported using user secret, this was referred to appsettings which I think I will go with that direction. – Offir Jan 28 '21 at 08:22