Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested web.config transform

I have a subdirectory with a simple web.config

<configuration>
  <system.web>
    <!--<authorization>
      <allow roles="admin"/>
      <deny users="*"/>
    </authorization>-->
  </system.web>
</configuration>

I like to have security turned off in development. I like to do a quick deploy - Alt-B-H

Problem: Can I use my main web.release.config to take off the comments?

like image 524
Dave Mateer Avatar asked Feb 15 '11 04:02

Dave Mateer


People also ask

What is Xdt transform replace?

A Transform attribute on a parent element can affect child elements even if no Transform is specified for them. For example, if you put the attribute xdt:Transform="Replace" in the system. web element, all the elements that are children of the system. web element are replaced with the content from the transform file.

What is Web config transform?

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.

What is Xdt transformation?

XDT is a simple and straight forward method of transforming the web. config during publishing/packaging. Transformation actions are specified using XML attributes defined in the XML-Document-Transform namespace, that is mapped to the xdt prefix.

How do I create a new transformation in web config?

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

You can't remove comments with a config transform. However, you can remove the entire authorization element and all of its child elements.

Try placing the following in your Web.Debug.config:

<configuration>
  <system.web>
    <authorization xdt:Transform="Remove"/>
  </system.web>
</configuration>
like image 136
John Saunders Avatar answered Oct 19 '22 00:10

John Saunders


I think you're looking at it the wrong way around Dave. Config transforms only get applied in a publish process which means when you're running locally (I assume this is what you mean by "turned off in development"), your web.config needs to be in the correct state for your local environment. If you don't want the auth node locally but you do want it remotely, you'll need config transforms to add it in the web.release.config file.

like image 20
Troy Hunt Avatar answered Oct 19 '22 02:10

Troy Hunt