0

我需要以下设置:

  • 在调试我的应用程序时,我希望我的connectionStrings配置部分通过加密aspnet_regiis
  • 发布应用程序时,连接字符串应该是正常的、未加密<add>的元素,其中的值只包含一些占位符文本。

我的理由是:

  1. 将代码推送到远程仓库时,我不希望我的调试凭据以明文形式保存在那里(因此是加密部分)
  2. 将应用程序发布到 Azure 时,我可以覆盖来自 azure 门户的占位符、未加密的连接字符串

这可以使用配置转换吗?

我可以找到转换单个连接字符串元素的唯一示例,但我需要整个部分看起来不同,具体取决于调试/发布设置。

感谢任何建议

4

1 回答 1

0

在这篇有用的帖子的帮助下,我设法做到了这一点:

<connectionStrings xdt:Transform="RemoveAttributes(configProtectionProvider)">
    <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
        xmlns="http://www.w3.org/2001/04/xmlenc#" xdt:Transform="Remove" xdt:Locator="Match(Type)" />

    <add xdt:Transform="Insert" name="CDSsvcUsername" connectionString="username"/>
    <add xdt:Transform="Insert" name="CDSsvcPassword" connectionString="password"/>
</connectionStrings>

所以我呼吁xdt:Transform="Remove"整个Encrypted元素以及configProtectionProvider删除connectionStrings.

这仅在xdt:Locator删除转换中指定后才有效。

于 2018-02-21T02:03:07.817 回答