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?
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.
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.
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.
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).
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With