Search code examples
asp.netxsltweb-config-transformxdt-transform

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>

Solution

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