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

走远了吗. 提交于 2019-12-23 07:05:03

问题


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.


回答1:


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.




回答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>


来源:https://stackoverflow.com/questions/24182473/xdttransform-insert-not-working-for-rewrite-in-system-webserver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!