I am trying to implement the following URL Rewrite config using appcmd
<system.webServer><rewrite><outboundRules><rule name="Add HttpOnly" preCondition="No HttpOnly"><match serverVariable="RESPONSE_Set_Cookie" pattern=".*" negate="false" /><action type="Rewrite" value="{R:0}; HttpOnly" /><conditions></conditions></rule><preConditions><preCondition name="No HttpOnly"><add input="{RESPONSE_Set_Cookie}" pattern="." /><add input="{RESPONSE_Set_Cookie}" pattern="; HttpOnly" negate="true" /></preCondition></preConditions></outboundRules></rewrite></system.webServer>
I can apply the 'preConditions' configuration with appcmd using the following:
appcmd.exe set config -section:system.webServer/rewrite/outboundRules /+"preConditions.[name='No HttpOnly']" /commit:apphost appcmd.exe set config -section:system.webServer/rewrite/outboundRules /+"preConditions.[name='No HttpOnly'].[input='{RESPONSE_Set_Cookie}',pattern='.']" /commit:apphost appcmd.exe set config -section:system.webServer/rewrite/outboundRules /+"preConditions.[name='No HttpOnly'].[input='{RESPONSE_Set_Cookie}',pattern='; HttpOnly',negate='True']" /commit:apphost
However I am getting an error when tying to configure the rule using the following
appcmd.exe set config -section:system.webServer/rewrite/outboundRules /+"[name='HttpOnly',preCondition='No HttpOnly']" /commit:apphost appcmd.exe set config -section:system.webServer/rewrite/outboundRules /[name='HttpOnly',preCondition='No HttpOnly'].match.serverVariable:"RESPONSE_Set_Cookie" /[name='HttpOnly',preCondition='No HttpOnly'].match.pattern:".*" /commit:apphost appcmd.exe set config -section:system.webServer/rewrite/outboundRules /[name='HttpOnly',preCondition='No HttpOnly'].action.type:"Rewrite" /[name='HttpOnly',preCondition='No HttpOnly'].action.value:"{R:0}; HttpOnly" /commit:apphost
The first cmd correctly creates the rule name and precondition. However the next two cmds generate errors:
Failed to process input: Duplicate parameters passed: [name=HttpOnly (HRESULT=800700b7).
All of the command lines were generated by IIS's Configuration Editor.
Any ideas about how to get this configuration scripted?
Thanks