Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 938
Yasser Shaikh Avatar asked Jun 12 '14 10:06

Yasser Shaikh


2 Answers

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.

like image 84
SteveChapman Avatar answered Oct 07 '22 18:10

SteveChapman


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>
like image 29
IsolatedStorage Avatar answered Oct 07 '22 16:10

IsolatedStorage