简体   繁体   中英

How to encrypt connection strings section when debugging

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM