As they state, user secrets is only for development (to avoid commiting credentials accidentally into the SCM) and not intended for production. You should use one connection string per database, i.e. ConnectionStrings:CmsDatabaseProduction
,ConnectionStrings:CmsDatabaseDevelopment
, etc.
Or use docker containers (when you're not using Azure App Service), then you can set it on per container basis.
Alternatively you can also use environment based appsetting files. appsettings.production.json
, but they must not be included in the source control management (Git, CSV, TFS)!
In the startup just do:
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
This way, you can load specific stuff from the appsettings.production.json
and can still override it via environment variable.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…