xdt:Transform="Insert" not working for <rewrite> in <system.webServer>
Asked Answered
V

2

12

I have the following transform written in the live config of my web.config.

<system.webServer>
    <rewrite xdt:Transform="Insert">
      <rules>
        <rule name="httpsrewrite">
          <match url=".*" />
          <serverVariables>
            <set name="SERVER_PORT" value="443" />
            <set name="HTTPS" value="on" />
          </serverVariables>
          <action type="None" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>

There is no element in my web.config.

The transform just does not work. All my other transform (replace for elmah and connection string) work fine.

Violante answered 12/6, 2014 at 10:46 Comment(1)
I am having the same issue as the OP. I use transformations on a bunch of other elements without issues. The <system.webServer> exists so that is not the issue.Shrovetide
L
3

Without seeing your source files it's hard to give a definitive answer.

In your web.config file you must have a /configuration/system.webServer element present for the transform to work. If you do not have it then there is no element for which to insert the /configuration/system.webServer/rewrite element.

If this doesn't help, please post at least the structure of both your web.config and the transform file. Also I suggest you install the SlowCheetah VS extension which is great for troubleshooting / previewing transforms.

Little answered 12/6, 2014 at 12:9 Comment(0)
M
2

I found that the xdt:Locator and xdt:Transform still works on the <rewrite> elements even though Visual Studio still generates warning messages (The 'http://schemas.microsoft.com/XML-Document-Transform:Locator' attribute is not declared).

<system.webServer>
    <rewrite>
        <rules>
            <clear />
            <rule name="Service Only Request Blocking Rule 1" stopProcessing="true" xdt:Locator="Match(name)" xdt:Transform="Replace">
                <match url=".*" />
                <conditions>
                    <add input="{URL}" pattern="\/address\/search\/.*$" />
                </conditions>
                <action type="CustomResponse" statusCode="403" statusReason="Forbidden: Access is denied." statusDescription="You do not have permission to complete this operation." />
            </rule>
        </rules>
    </rewrite>
</system.webServer>
Monica answered 24/6, 2015 at 4:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.