代码之家  ›  专栏  ›  技术社区  ›  Bassie

调试时如何加密连接字符串部分

  •  0
  • Bassie  · 技术社区  · 7 年前

    我需要以下设置:

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

    我的理由是:

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

    这是否可以使用配置转换?

    我能找到的唯一示例是转换单个连接字符串元素,但我需要整个部分根据调试/发布设置看起来有所不同。

    感谢您的建议

    1 回复  |  直到 7 年前
        1
  •  0
  •   Bassie    7 年前

    我在 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>
    

    所以我打电话来 xdt:Transform="Remove" 总的来说 Encrypted 元素以及移除 configProtectionProvider 属性打开 connectionStrings .

    仅在指定 xdt:Locator 在删除转换中。