In my release web.configs I’m using conditionals (#{if Variable} stuff #{/if}), and while this is working great in a lot of areas, I tried adding it to another area and it failed completely.
Here is an example of it working:
<system.serviceModel>
<bindings>
#{if secureOnly}
<basicHttpBinding xdt:Transform="Replace">
<binding transferMode="Streamed" maxReceivedMessageSize="100000000000" sendTimeout="00:30:00">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
#{/if}
<wsHttpBinding>
<binding>
#{if secureOnly}
<security mode="Transport" xdt:Transform="Replace">
<transport clientCredentialType="None" />
</security>
#{/if}
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
And here is what I want to do:
<system.webServer>
#{if IsWebserver}
<rewrite xdt:Transform="Insert">
<rules>
<rule name="Subdomain mapping" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^webappsite\.#{domain.webappsite}$" negate="true"/>
<add input="{HTTP_HOST}" pattern="^([^.]+).[^.]+"/>
</conditions>
#{if secureOnly}
<action type="Redirect" url="https://webappsite.#{domain.webappsite}/{C:1}"/>
#{/if}
#{unless secureOnly}
<action type="Redirect" url="http://webappsite.#{domain.webappsite}/{C:1}"/>
#{/if}
</rule>
</rules>
</rewrite>
#{/if}
</system.webServer>
And here is what I have to do to get it to work:
<system.webServer>
<rewrite #{if IsWebserver}xdt:Transform="Insert"#{/if}>
<rules>
<rule name="Subdomain mapping" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^webappsite\.#{domain.webappsite}$" negate="true"/>
<add input="{HTTP_HOST}" pattern="^([^.]+).[^.]+"/>
</conditions>
<action type="Redirect" url="http#{if secureOnly}s#{/if}://webappsite.#{domain.webappsite}/{C:1}"/>
</rule>
</rules>
</rewrite>
</system.webServer>
So for some reason it seems that within that certain tag it doesn’t work if the “if” is in the empty space.