[英]IIS Dynamic Compression and ASP.NET Core
I have an ASP.NET Core v2.2 application deployed to IIS.我有一个部署到 IIS 的 ASP.NET Core v2.2 应用程序。 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 .
我遵循使用 IIS 动态压缩而不是响应压缩中间件的建议,如ASP.NET Core中的响应压缩中所述。 I used the IIS Management Tool to configure the dynamic compression in IIS and it's working as expected.
我使用 IIS 管理工具在 IIS 中配置动态压缩,它按预期工作。 However, this updates the application's web.config to include a urlCompression element.
但是,这会更新应用程序的 web.config 以包含 urlCompression 元素。
<?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.我的问题是,下次我发布应用程序时,动态压缩设置会丢失,我必须返回 IIS 管理工具重新配置它。
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?如何确保在重新发布我的应用程序后保留此设置,而不必每次都进入 IIS 管理工具?
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?有没有办法在 Visual Studio 项目中包含此动态压缩设置,以便将其包含在生成的 web.config 文件中?
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.您可以在项目的根目录中创建一个“web.config”文件,发布后内容将与生成的“web.config”文件中的其他生成内容合并。
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:发布位置的“web.config”文件内容:
<?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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.