Reputation: 1367
I have an ASP.NET Core v2.2 application deployed to IIS. I'm following the recommendation of using IIS dynamic compression rather than the response compression middleware as stated in Response compression in ASP.NET Core. I used the IIS Management Tool to configure the dynamic compression in IIS and it's working as expected. However, this updates the application's web.config to include a urlCompression element.
<?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=".\xyz.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
<system.webServer>
<urlCompression doDynamicCompression="true" />
</system.webServer>
</configuration>
My issue is that the next time I publish the application the dynamic compression setting is lost and I have to go back into the IIS Management Tool to configure it again.
How do I ensure this setting is preserved after re-publishing my application and without having to go into the IIS Management Tool every time?
Is there a way to include this dynamic compression setting in the Visual Studio project so it's included in the generated web.config file?
Upvotes: 2
Views: 1639
Reputation: 739
You can create a "web.config" file in the root of your project, and the contents will be merged with the other generated content in the resulting "web.config" file after publishing.
Example project file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<urlCompression doDynamicCompression="true" />
</system.webServer>
</configuration>
Contents of "web.config" file at the published location:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<urlCompression doDynamicCompression="true" />
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\xxx.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</configuration>
Upvotes: 1