.Net Web.Config Transformations, replace entire ConnectionString section

2.2k views Asked by At

I've been using web.config transforms with good success. I've just recently implemented connection strings encryption and am unsure how to modify my Release transform.

Before hand I was simply replacing the setting by using the locator for name.

Now that the settings are encrypted, there is no name.

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

How can I update my transform to replace the entire connection strings section with this? Is there a locator for the element name "connectionStrings"?

Many thanks, John

2

There are 2 answers

0
John Mc On

Never mind, if you leave out the Locator it automatically applies it to the element.

0
Mahesh On

To replace entire connectionString section use the below code

<connectionStrings xdt:Transform="Replace">

xdt:Transform="Replace" Will do the trick. Cheers!!