Search code examples
c#.net-coreweb.config-transform

Web.config transform removes Security and HttpProtocol node


When I publish my Dotnet Core (2.x) application to my Release configuration the Web.config is not transformed properly.

Ofcourse it has the Handlers and aspNet Core elements in it but all te httpProtocol and Security nodes are completely gone! Am I missing something here?

Base / Dev Web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" requestTimeout="00:10:00" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
      <security>
        <requestFiltering>
          <requestLimits maxAllowedContentLength="524288000" />
        </requestFiltering>
      </security>
      <httpProtocol>
        <customHeaders>
          <add name="Access-Control-Allow-Origin" value="*" />
        </customHeaders>
      </httpProtocol>
    </system.webServer>
  </location>
</configuration>

And after a dotnet publish --configuration Server -o C:\MyWebs\publish

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\project.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
    </system.webServer>
  </location>
</configuration>

Cheers.


Solution

  • Fixed it eventually using a Web.release.config and insert the specific httpProtocol and Security nodes with xdt:Transform.

    <httpProtocol xdt:Transform="Insert">
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
      </customHeaders>
    </httpProtocol>