Core应用程序生产环境的连接字符串

Core应用程序生产环境的连接字符串

本文介绍了我应该在哪里存储ASP.NET Core应用程序生产环境的连接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在部署到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应用程序生产环境的连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 20:25