Search code examples
.netweb-config-transform

Adding static content in web config transform


I have a Web.Config file for local testing and i have a web.Release.Deploy.config transform that i want to include static content into. I am not very familiar with web config transforms. I have added this to the web.release.deploy.config.

 <system.webServer xdt:Transform="Insert">
    <staticContent>
      <mimeMap fileExtension=".nupkg" mimeType="application/zip" />
      <remove fileExtension=".woff" />
      <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
      <mimeMap fileExtension=".woff2" mimeType="application/x-font-woff2" />
    </staticContent>
  </system.webServer>

Should i be adding a rule to this or does the syntax look correct?

or should it look like this since the system.webserver element is not being inserted only the static content?

 <staticContent xdt:Transform="Insert">
      <mimeMap fileExtension=".nupkg" mimeType="application/zip" />
      <remove fileExtension=".woff" />
      <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
      <mimeMap fileExtension=".woff2" mimeType="application/x-font-woff2" />
    </staticContent>

Solution

  • The answer that worked for me was this.

     <staticContent xdt:Transform="InsertIfMissing">
          <mimeMap fileExtension=".nupkg" mimeType="application/zip" />
          <remove fileExtension=".woff" />
          <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
          <mimeMap fileExtension=".woff2" mimeType="application/x-font-woff2" />
        </staticContent>
    

    this worked because the insert is on the static content tag. Hope this helps.