Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to "insert" a new section into Web.Config using transforms?

In my Web.Config I have the following

  <system.webServer>

    <modules>
       **some code**
    </modules>
    <handlers>
       **some code**    
    </handlers>

  </system.webServer>

How do I transform it so I can inject a new sub section for "security" into "system.webServer"? Everything I have tried and search on so far has failed.

What I desire is shown below:

  <system.webServer>

    <modules>
       **some code**
    </modules>
    <handlers>
       **some code**    
    </handlers>

    <security>
      <ipSecurity allowUnlisted="false" denyAction="NotFound">
        <add allowed="true" ipAddress="10.148.176.10" />
      </ipSecurity>
    </security>

  </system.webServer>
like image 524
Paul Brown Avatar asked May 17 '14 09:05

Paul Brown


People also ask

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).

What is Xdt transform in web config?

A transform file is an XML file that specifies how the Web. config file should be changed when it is deployed. Transformation actions are specified by using XML attributes that are defined in the XML-Document-Transform namespace, which is mapped to the xdt prefix.

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.


1 Answers

Found the solution that worked. Within my Web.Azure.Config file I had to add the following:

  <system.webServer>
    <security xdt:Transform="Insert">
      <ipSecurity allowUnlisted="false" denyAction="NotFound">
        <add allowed="true" ipAddress="10.148.176.10" />
      </ipSecurity>
    </security>
  </system.webServer>

I tried this before posting the question but due to a typo in another part of Web.Config it was erroring.

like image 134
Paul Brown Avatar answered Sep 28 '22 18:09

Paul Brown