Conditional Variable Usage doesn't work in some places

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.

Hi,

Thanks for getting in touch and providing excellent example input. It really helps! I reproduced the issue but I was able to get it working by doing the following.

  • Minor typo in the “what I want to do” transform as you closed the #{unless} conditional with an #{/if} instead of #{/unless}
  • Turned on Substitute variables in files Package Step feature and specified the transform file. Similar to the attached screenshot.

Hope this helps!

Rob

Wow, I wouldn’t call that a minor typo! Thanks for picking that out.

It would be nice to have some messaging around this in the log since it failed the whole file and didn’t show anything even in the verbose log with variable debugging on.

Hi,

I’m happy I could help and thanks for the feedback. I’ll keep in in mind the next time we work on Octostache (the feature that powers the extended syntax).

Thanks

Rob