【问题标题】:How to encrypt connection strings section when debugging调试时如何加密连接字符串部分
【发布时间】:2018-02-21 01:40:36
【问题描述】:
我需要以下设置:
- 调试我的应用程序时,我希望我的
connectionStrings 配置部分通过aspnet_regiis 加密
- 发布应用程序时,连接字符串应该是正常的、未加密的
<add>元素,其中的值只包含一些占位符文本。
我的理由是:
- 将代码推送到远程仓库时,我不希望我的调试凭据以明文形式保存在那里(因此是加密部分)
- 将应用程序发布到 Azure 时,我可以覆盖占位符、来自 azure 门户的未加密连接字符串
这可以使用配置转换吗?
我能找到的唯一示例转换单个连接字符串元素,但我需要整个部分看起来不同,具体取决于调试/发布设置。
感谢任何建议
【问题讨论】:
标签:
azure
web-config
connection-string
aspnet-regiis.exe
【解决方案1】:
我在this useful post 的帮助下做到了这一点:
<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>
所以我在整个Encrypted 元素上调用xdt:Transform="Remove",并删除connectionStrings 上的configProtectionProvider 属性。
这仅在删除转换中指定 xdt:Locator 后才有效。