In ASP.Net Core, when publishing the project, the web.config file is generated with some default data.
Example:
<configuration>
<system.webServer>
<handlers>
<add modules="AspNetCoreModule" name="aspNetCore" path="*" resourceType="Unspecified" verb="*" />
</handlers>
<aspNetCore processPath=".\My.WebApp.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
At times, you may need to override the contents of this file or change the values of some of the keys. To do this, simply add a web.config file to your ASP.Net Core project. You can add the file through the usual way of right-clicking the project and choosing "Add -> New Item…". Next, browse through the list of available templates and select Web Configuration File. This will add a new web.config file to your project with a commented out template which you can modify to fit your needs.
Example:
<configuration>
</configuration>
Simply uncomment the section and change, or add, any values you need.
In the following example, I want to remove the
arguments attribute as my application does not require it, and override the value of the
processPath; my application exe is located in a sub folder named “bin”.
Example:
<configuration>
<system.webServer>
<handlers>
<add modules="AspNetCoreModule" name="aspNetCore" path="*" resourceType="Unspecified" verb="*" />
</handlers>
<aspNetCore processPath=".\bin\My.WebApp.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
By adding the web.config file, most of the values in the web.config will be overridden when the project is published. However, for some reason, the customized processPath value gets ignored and the automatic generated value gets outputted instead. To fix this issue, you will need to modify your project file and add a new keyword to your Publish build profiles;
IsTransformWebConfigDisabled. This will ensure that whatever you put in your web.config remains.
Example:
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<PlatformTarget>x86</PlatformTarget>
<DocumentationFile>.\bin\Release\net472\My.WebApp.xml</DocumentationFile>
<NoWarn>1701;1702;1705;1591;NU1603</NoWarn>
<Optimize>false</Optimize>
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
</PropertyGroup>