It seems that the best solution for deployment would be to specify in the Web.Azure.Config, as you specified in your answer.
Just for fun, posting this XSLT solution that you could also use to either add the <security>
element with the IP address if it did not exist, or invoke later to add additional entries. Set the IP address in the ipAddress
parameter when executing. If no ipAddress
is specified, it does nothing.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="ipAddress"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!--Create security/ipSecurity with specified IP address,
if specified in param-->
<xsl:template match="system.webServer[not(security)]">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:if test="$ipAddress">
<security>
<ipSecurity allowUnlisted="false" denyAction="NotFound">
<add allowed="true" ipAddress="{$ipAddress}" />
</ipSecurity>
</security>
</xsl:if>
</xsl:copy>
</xsl:template>
<!--Add an allowed IP address to existing security/ipSecurity entry,
if IP address is specified in param -->
<xsl:template match="security/ipSecurity">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:if test="$ipAddress">
<add allowed="true" ipAddress="{$ipAddress}" />
</xsl:if>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
web.config
will trigger an app restart. You could of course generate it from a transform during deployment, but it looks like the OP wants to use an IP address based on the server itself. That might be possible (depending on the hosting setup) though it has nothing to do with XSLT as such. – Unhesitating