0

I need the following setup:

  • When debugging my application, I want my connectionStrings config section to be encrypted via aspnet_regiis
  • When publishing the application, connection strings should be normal, unencrypted <add> elements, where the value just contains some placeholder text.

My reasoning is:

  1. When pushing the code to remote repo, i don't want my debug credentials to be saved there in plaintext (hence the encrypted section)
  2. When publishing the app to Azure, I can override the placeholder, unencrypted connection strings from azure portal

Is this possible using config transformations?

The only examples I can find transform individual connection string elements, but I need the entire section to look different depending on debug/release settings.

Appreciate any advice

Bassie
  • 9,529
  • 8
  • 68
  • 159

1 Answers1

0

I managed to do this with the help of 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>

So I'm calling xdt:Transform="Remove" on the entire Encrypted element as well as removing the configProtectionProvider attribute on connectionStrings.

This only worked after specifying xdt:Locator in the remove transformation.

Bassie
  • 9,529
  • 8
  • 68
  • 159