加密连接字符串 IIS 7

Encrypt connection String IIS 7

我正在使用 TFS 2017 Realese 定义来部署我的网站,我的密码和用户名环境变量是隐藏的,但是当连接字符串被传递时 Web.config 文件显示密码和用户名如何加密连接字符串在 web.config 文件中?

您可以在命令提示符中运行此命令(cmd.exe):

%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -pe "connectionStrings" -app "/SampleApplication"

其中 SampleApplication 是您的应用程序在 IIS 中的名称 有关详细信息,请参阅 this article

更新

要加密 web.config 文件中的连接字符串,TFS 构建任务无法执行此操作。它与IIS更相关。建议你看看这个博客:Encrypting connectionStrings in Web.Config using the NetFrameworkConfigurationKey in an IIS Web Farm scenario


您可以尝试在 VSTS 发布期间将 web.config 中的特定值替换为 Replace Token task。示例屏幕截图:

For this configuration of Replace Token task, it can replace #{con}# to the con variable value (Create a variable (variable name: con) in Variable tab of build definition) for all .config files (have #{con}# code) in $(System.DefaultWorkingDirectory) location.

<connectionStrings>
    <add name="DefaultConnection" connectionString="#{con}#" providerName="System.Data.SqlClient" />
  </connectionStrings>

我使用@Arman answer 让它工作但不得不稍微修改它,我必须默认指定网站编号它的 1 这是一个不同的网站检查这个 link 如何找到你的网站数字。 link

%%windir%%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -pe "connectionStrings" -app "/" -site "2"

在我的例子中,该站点是 2 号。此外,您还必须 运行 作为管理员的命令提示符。

感谢您的所有回答。

您必须浏览 aspnet_regiis,然后使用 pdf 和 pdf 命令以及部分名称和 Web 配置文件的路径执行命令。