Connection strings on Azure PaaS

After you have provisioned your Sitecore application in Azure PaaS, you will notice that in the webroot the connectionstring file has been generated in <<webroot>>/App_Config/ConnectionStrings.config

To improve security, in Azure, you have also the possibility to store and manage the connection strings on the app service.

Copy pasting all the connection strings from the original connection string file into the Azure interface can be a boring tedious job. Luckily with the advanced edit you can now edit the connection strings in JSON format.

Since the original format of the connection strings is a file in XML format. We could apply good a old XSL transformation to convert the xml file into the json format Azure requests.

<?xml version="1.0"?><xsl:stylesheet version="1.0"xmlns:xsl=""><xsl:output method="text"/><xsl:template match="/">[ <xsl:for-each select="connectionStrings/add"><xsl:choose><xsl:when test="string(@connectionString)">{"name": "<xsl:value-of select="@name"/>","value": "<xsl:value-of select="@connectionString"/>","type": "Custom","slotSetting": false}<xsl:choose><xsl:when test="position() != last()">,</xsl:when></xsl:choose></xsl:when></xsl:choose></xsl:for-each>]</xsl:template></xsl:stylesheet>

To convert your xml file, you can use the xsl stylesheet mentioned here above. To do the transformation you can link the stylesheet on the xml document like this:

<?xml version=”1.0″ encoding=”UTF-8″?>
<?xml-stylesheet type=”text/xsl” href=”connectionstrings.xsl”?>

Leave a Reply

Your email address will not be published. Required fields are marked *