Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make URL rewrite work with web.Release.config transform?

I have a web.config rewrite rule specified to move all traffic to https. The rule works, but I don't want SSL required while I am debugging. I have a bunch of web.release.config transformations being done already that work on publish so I decided to put a rewrite rule in there. The problem is that the rewrite rule isn't being transformed like the rest of the settings. Here is the web.config setup:

<system.webServer>     <validation validateIntegratedModeConfiguration="false"/>     <modules runAllManagedModulesForAllRequests="true"/>      <rewrite></rewrite> </system.webServer> 

And here is the transformation being done:

  <system.webServer> <rewrite>   <rules>     <rule name="Redirect HTTP to HTTPS" stopProcessing="true">       <match url="(.*)"/>       <conditions>         <add input="{HTTPS}" pattern="^OFF$"/>       </conditions>       <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther"/>     </rule>   </rules> </rewrite></system.webServer> 

If I just copy the rewrite rule to the web.config it works fine. Does anyone out there have any ideas why web.Release.config transforms aren't working for only this section?

like image 531
Matthew Kruskamp Avatar asked Aug 09 '11 23:08

Matthew Kruskamp


People also ask

How does web config transform work?

A Web. config transformation file contains XML markup that specifies how to change the Web. config file when it is deployed. You can specify different changes for specific build configurations and for specific publish profiles.

Does installing URL Rewrite require a reboot?

To install the IIS URL Rewrite module: Go Here and click install… Or just click here. Once installed you may need to reboot.


1 Answers

Transformation will only happen if you put proper xdt attributes on the elements that need to be transformed. Try adding an xdt:Transform attribute to your release config:

<system.webServer xdt:Transform="Replace">     <!-- the rest of your element goes here --> </system.webServer> 

That will tell the transformation engine that the entire system.webServer element from Web.config needs to be replaced with the one from Web.Release.config.

The transformation engine will silently ignore any elements that do not have xdt attributes.

Obligatory link to MSDN.

like image 120
Lobstrosity Avatar answered Sep 20 '22 05:09

Lobstrosity