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.

jcjr
  • 1,503
  • 24
  • 40
Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281
  • 1
    I am having the same issue as the OP. I use transformations on a bunch of other elements without issues. The exists so that is not the issue. – SynBiotik May 14 '16 at 02:16

2 Answers2

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.

SteveChapman
  • 3,051
  • 1
  • 22
  • 37
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>
IsolatedStorage
  • 1,175
  • 12
  • 12