.Net Web.Config转换,替换整个ConnectionString部分

Joh*_* Mc 4 .net web-config-transform

我一直在使用web.config转换,效果很好。我最近刚刚实现了连接字符串加密,并且不确定如何修改我的Release转换。

之前,我只是使用定位器来替换名称设置。

现在设置已加密,现在没有名称了。

<connectionStrings configProtectionProvider="Pkcs12Provider">
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
  xmlns="http://www.w3.org/2001/04/xmlenc#">
  <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes192-cbc" />
  <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
    <EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
      <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
      <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
        <KeyName>rsaKey</KeyName>
      </KeyInfo>
      <CipherData>
        <CipherValue>CipherValueHere</CipherValue>
      </CipherData>
    </EncryptedKey>
  </KeyInfo>
  <CipherData>
    <CipherValue>CipherValueHere</CipherValue>
  </CipherData>
</EncryptedData>
Run Code Online (Sandbox Code Playgroud)

如何更新我的转换,以替换整个连接字符串部分?元素名称“ connectionStrings”是否有定位符?

非常感谢,约翰

小智 5

要替换整个connectionString部分,请使用以下代码

<connectionStrings xdt:Transform="Replace">
Run Code Online (Sandbox Code Playgroud)

xdt:Transform="Replace"会成功的。干杯!!


Joh*_* Mc 4

没关系,如果您省略定位器,它会自动将其应用到元素。