到目前为止,我一直在使用 gitignore 来忽略我的 web.congfig 和 web.release.config 文件,这样我的连接字符串(包括密码)就不会存储在 git 存储库中。
这对在加密的可移动媒体上传递的 web.config 的更改很好。
但我刚刚开始考虑使用持续集成并将我的代码存储在 Visual Studio Team Services 上。为此,我必须将 web.config 作为项目的一部分包含在内(除非您可以提出修复建议)。
我在带有 MSSQL 数据库的 Windows 服务器(内部)上托管应用程序,并连接到不同服务器上的 Oracle 数据库。
我不是最先进的开发人员,但到目前为止我自己的。非常欢迎大家的支持。
最佳答案
您可以通过将连接字符串详细信息移至外部配置文件来实现。假设您将连接字符串移动到 connections.config 文件
<connectionStrings>
<add name="Name"
providerName="System.Data.ProviderName"
connectionString="Valid Connection String;" />
</connectionStrings>
现在在网络配置中,您可以将此文件作为连接字符串引用
<?xml version='1.0' encoding='utf-8'?>
<configuration>
<connectionStrings configSource="connections.config"/>
</configuration>
More detail about external configuration file
之后你可以在 gitignore 文件中列出你的 connections.config 文件
然后推送到你的 git 仓库。
But make sure that your readme file contains necessary settings to apply to make your app working for other developer. As you have moved your connection details to another file other may not be familiar with that approach and may cause some issue.
关于c# - 如何在 git 存储库中保证 ASP.net 连接字符串密码的安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45677569/