Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove section in web.config file in debug mode

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)

like image 458
bzamfir Avatar asked May 03 '14 20:05

bzamfir


People also ask

What is Xdt transform in web config?

The xdt:Transform attribute value "SetAttributes" indicates that the purpose of this transform is to change attribute values of an existing element in the Web. config file.

How to add web config transformation file?

If you have a web application project, Right-click on web. config and choose Add Config Transform. This will add any config transforms that are missing from your project based on build configurations (i.e. if you have Production and Staging build configs, both will get a transform added).


2 Answers

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

<system.webServer>
   <rewrite xdt:Transform="Remove" >
   </rewrite>
 </system.webServer>
like image 64
CrIceIs Avatar answered Sep 24 '22 21:09

CrIceIs


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>
like image 20
bzamfir Avatar answered Sep 24 '22 21:09

bzamfir