问题描述
在部署到 IIS 7(不是 Azure)时,生产和暂存连接字符串应该存储在 ASP.NET Core 应用程序中的什么位置?
Where should the production and staging connection strings be stored in an ASP.NET Core application, when deploying into IIS 7 (not Azure) ?
我正在寻找推荐的方法/最佳实践,尤其是在安全方面.
I am looking for the recommended way of doing it / best-practice, especially security-wise.
推荐答案
在 ASP.NET 5 中可以指定多个配置源.由于对先前模型的这种欢迎更改,您可以将开发连接字符串存储在简单的 json 文件中,并将暂存和生产连接字符串直接存储在相应服务器上的环境变量中.
In ASP.NET 5 it's possible to specify multiple configuration sources. Thanks to this welcoming change to previous model you can store your development connection string in simple json file, and your staging and production connection string in environment variables directly on the respective servers.
如果你像这样配置你的应用程序:
If you configure your app like this :
var config = new Configuration()
.AddJsonFile("config.json")
.AddEnvironmentVariables();
并且config.json和环境变量中都有连接字符串,那么环境源将获胜.
and there is connection string in both config.json and environment variable then environment source will win.
因此,将您的开发连接字符串存储在 config.json 中(并在源代码管理中自由签入)并将生产连接字符串存储在环境变量中.更多信息这里和这里.
So, store your development connection string in config.json(and freely check in in source control) and production one in environment variable. More info here and here.
这篇关于我应该在哪里存储 ASP.NET Core 应用程序的生产环境的连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!