c# - 如何在 git 存储库中保证 ASP.net 连接字符串密码的安全?

标签 c# asp.net git continuous-integration

到目前为止,我一直在使用 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/

相关文章:

c# - InternalsVisibleTo、Signing 和 Unit tests,如何落地?

c# - 寻找将负整数归零的 .NET Math 方法

asp.net - 无法建立连接,因为目标机器主动拒绝

svn - 用 git-svn cherry-pick

git - GitHub 中的比较工具(比较发行版,或在必要时比较 shas)

c# - 父 View 内的部分 View 不向 Controller 发送数据 - asp.net MVC

c# - 如何通过 "Microsoft print to PDF"以编程方式将文件和网页打印为 PDF?

javascript - 如何在 Notes 实体字段上应用 REQUIRED FIELD 验证?

asp.net - 如何在 IIS 中发布 Blazor ASP.NET 应用程序?

git - 回滚到 Mercurial 中的旧版本(如 git reset)