Remove section in web.config file in debug mode
Asked Answered
H

4

12

I have an asp.net application, which must run under SSL, and it has some rewrite rules defined in web.config to accomplish this.

<!--file web.config -->
....
</system.webServer>
  <rewrite>
    <rules configSource="webrewrite.config" />
  </rewrite>
</system.webServer>


<!--file web.config -->
<rules>
  ....    
  <rule name="HTTP to HTTPS redirect" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
      <add input="{HTTPS}" pattern="off" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
  </rule>
  ....
</rules>

However, in development mode (with local web server or IIS Express) I don't want to use SSL. So I would like to be able to use web.config transformations to remove one or more rewrite rules (but not all)

Holozoic answered 3/5, 2014 at 20:53 Comment(0)
H
7

I solved the problem, by using Remove transform, as shown below

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  ....
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="RulaNameToRemove"
          xdt:Transform="Remove"
          xdt:Locator="Match(name)" >
        </rule>
      </rules>
    </rewrite>    
  </system.webServer>
</configuration>
Holozoic answered 3/5, 2014 at 21:19 Comment(1)
it is permanently deleted from web config file but in release mode rewrite rules required so need to write in web.config.release also and with Insert modeOviduct
F
8

If you want to remove the Entire Section for your Dev Configuration use

<system.webServer>
   <rewrite xdt:Transform="Remove" >
   </rewrite>
 </system.webServer>
Fishwife answered 9/4, 2018 at 22:24 Comment(0)
H
7

I solved the problem, by using Remove transform, as shown below

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  ....
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="RulaNameToRemove"
          xdt:Transform="Remove"
          xdt:Locator="Match(name)" >
        </rule>
      </rules>
    </rewrite>    
  </system.webServer>
</configuration>
Holozoic answered 3/5, 2014 at 21:19 Comment(1)
it is permanently deleted from web config file but in release mode rewrite rules required so need to write in web.config.release also and with Insert modeOviduct
O
1

Please write below code web.Debug and web.Release config file. Web.Debug will delete rewrite rules and web.Release insert rewrite rules.

Web.Debug.config

  <system.webServer>
    <rewrite>
      <rules>
        <rule name="RulaNameToRemove"
          xdt:Transform="Remove"
          xdt:Locator="Match(name)" >
        </rule>
    </rewrite>    
  </system.webServer>
</configuration>

Web.Release.config

<system.webServer>
    <rewrite>
      <rules>
        <clear />
        <rule name="Redirect to https" stopProcessing="true" xdt:Transform="Insert">
          <match url=".*"/>
          <conditions>
            <add input="{HTTPS}" pattern="off" ignoreCase="true"/>
          </conditions>
          <action type="Redirect" url="https://{SERVER_NAME}" redirectType="Permanent"/>
         
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
Oviduct answered 3/7, 2020 at 10:46 Comment(0)
D
0

You can move release settings to web.config.release file

Daudet answered 6/2, 2020 at 20:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.