正如您在答案中指定的那样,部署的最佳解决方案似乎是在 Web.Azure.Config 中指定。
只是为了好玩,发布这个 XSLT 解决方案,您也可以使用它来添加<security>
带有 IP 地址的元素(如果它不存在),或者稍后调用以添加其他条目。ipAddress
执行时在参数中设置IP地址。如果没有ipAddress
指定,它什么也不做。
<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>