0
votes

When deploying web apps to Azure you can override the connection strings and app settings by setting these in the portal for the particular web app you are deploying. Is there any way you can override other parts of the web.config from the portal. I am using a plugin for the Umbraco CMS that requires connection strings in the web.config that are not in the appSetting section of the file. (they usually hold them in another file, but I have placed them in the web.config so I can hopefully set them from the portal)

Here is a sample of the configuration section of the web.config with only the relevant section I am referring to:

<configuration>
    ...A lot of other web.config stuff
  <imageProcessor>   
    <caching currentCache="AzureBlobCache">
      <caches>
        <cache name="AzureBlobCache" type="ImageProcessor.Web.Plugins.AzureBlobCache.AzureBlobCache, ImageProcessor.Web.Plugins.AzureBlobCache" maxDays="365">
          <settings>
            <!--Azure Cache Provider-->
            <setting key="CachedStorageAccount" value="Azure blob storage key" />
            <setting key="CachedBlobContainer" value="cache" />
            <setting key="UseCachedContainerInUrl" value="false" />
            <setting key="CachedCDNRoot" value="Azure storage account" />
            <setting key="CachedCDNTimeout" value="1000" />
            <setting key="SourceStorageAccount" value="name=Azure storage account" />
            <setting key="SourceBlobContainer" value="media" />
            <setting key="StreamCachedImage" value="false" />
          </settings>
        </cache>
      </caches>
    </caching>
  </imageProcessor>
</configuration>

What I would like to do is set the setting keys in the cache section above. If I am not able to refer directly to this section in the Azure portals appSettings section then can I put these settings in the appSettings section of the web.config as keys and refer to them from this section of the web.config file?

I know I can use web.config transforms to achieve this but this will still require me to check the connection strings into source control under web.config.release etc and I would prefer not to do this.

Is there another solution that I am overlooking that will perform the tasks I want? (The solution is hosted in VSTS so I could always add another build step with the settings keys there) That way they would end up associated with the build configuration rather than in source control.

1
Azure Web Apps can't do it. You can only override the stuff you see there.juunas
Well can you redirect the attention of the caches settings back to the appSettings section?Aran Mulholland
Only if that imageProcessor component supports it. Certain libraries allow specifying app setting keys instead of values.juunas

1 Answers

0
votes

You can add PowerShell Script as one of the steps in your build definition. If you use inline script option you don't need to have this script in your repo.

Script can look like this (I added a correct XPath as stated in your example).

$path = ".\web.config"
$xml = [xml](Get-Content $path)

$dictionary = @{
    CachedCDNTimeout = '9000'    
}

foreach ($key in $dictionary.Keys)
{    
    if (($addKey = $xml.SelectSingleNode("//configuration/imageProcessor/caching/caches/cache/settings/setting[@key = '$key']")))
    {        
        $addKey.SetAttribute('value', $dictionary[$key])
    }
}

$xml.Save($path)

(I've tested it only locally)