gpt4 book ai didi

asp.net-mvc - application/xhtml+xml 内容类型上的 GZip 压缩在 IIS 7.5/MVC 中不起作用

转载 作者:行者123 更新时间:2023-12-03 07:21:49 26 4
gpt4 key购买 nike

我有一个在启用了压缩的 IIS 7.5 上运行的 MVC3 站点。

GZip 压缩适用于网站的所有页面,除了我在 Controller 中手动将内容类型更改为 application/xhtml+xml 的少数页面(出于各种原因,这是必要的) (Response.ContentType = "application/xhtml+xml";)。

这种内容类型会导致 GZip 无法工作,有什么办法解决这个问题吗?

最佳答案

application/xhtml+xml 不是 IIS 压缩知道要压缩的内置 mime 类型之一。您必须显式启用此 mime 类型的压缩。

我假设您希望启用压缩,无论它是静态文件还是动态生成的。为此,您必须将 mime-type 添加到计算机级别配置的 system.webServer/httpCompression 中。 staticTypesdynamicTypes 部分。使用部署脚本执行此操作的更简单方法之一是仅使用 appcmd.exe,如下所示:

添加对压缩静态内容的支持

appcmd.exe set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='application/xhtml%%2bxml',enabled='True']" /commit:apphost

添加对压缩动态内容的支持

appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/xhtml%%2bxml',enabled='True']" /commit:apphost

显然,您可以对您可能想要压缩的任何其他内容类型使用相同的方法。

关于asp.net-mvc - application/xhtml+xml 内容类型上的 GZip 压缩在 IIS 7.5/MVC 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10147923/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com