在 IIS7.5 中未读取 web.config 中的 HttpCompression 元素

发布于 2024-12-14 16:49:58 字数 1144 浏览 1 评论 0原文

我试图覆盖运行 Windows 7 的 IIS 7.5 上的网站的 Web.config 中的 httpCompression 元素,但它似乎根本不被读取。

为了检查,我在元素中引入了 typeos,但我什至无法得到配置错误。

这是 Web.config 中的 httpCompression 元素的示例

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
  <SCHEMEx name="deflate" dll="%Windir%\system32\inetsrv\gzip.dll" />
  <dynamicTypes>
    <add mimeType="text/*" enabled="false" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/x-javascript" enabled="true" />
    <add mimeType="*/*" enabled="false" />
  </dynamicTypes>
  <staticTUPES>
  </staticTUPES>
</httpCompression>

当我在其他元素(如 modules)中引入类似错误时,我收到配置错误,所以我知道配置文件被读取。

我已经解锁了 ApplicationHost.config 中的部分:

appcmd unlock config /section:system.webserver/httpcompression

但这不起作用,所以我手动更改了 ApplicationHost.config,所以它现在显示为:

...
<section name="httpCompression" overrideModeDefault="Allow" />
...

我真正想要完成的是将“deflate”设置为唯一的压缩方案我的网站。

I'm trying to override the httpCompression element within Web.config for a site on an IIS 7.5 running Windows 7, but it does not seem to be read at all.

To check, I've introduced typeos within the element, but I can't even get a configuration error.

Here is an example of the httpCompression element from Web.config

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
  <SCHEMEx name="deflate" dll="%Windir%\system32\inetsrv\gzip.dll" />
  <dynamicTypes>
    <add mimeType="text/*" enabled="false" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/x-javascript" enabled="true" />
    <add mimeType="*/*" enabled="false" />
  </dynamicTypes>
  <staticTUPES>
  </staticTUPES>
</httpCompression>

When I introduce similar errors in other element (like ie modules) I get a configuration error, so I know the config file is read.

I've unlocked the section in ApplicationHost.config:

appcmd unlock config /section:system.webserver/httpcompression

But that did not work, so I changed ApplicationHost.config manually so it now reads:

...
<section name="httpCompression" overrideModeDefault="Allow" />
...

What I'm really trying to accomplish is to set "deflate" as the only compression scheme for one of my sites.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何以心动 2024-12-21 16:50:03

我之前也遇到过类似的问题,时间太久了记不清了。我想我直接对 ApplicationHost.config (%windir%\system32\inetsrv\config) 进行更改,但这不是理想的解决方案。

假设你已经看过这里
http://www.iis.net/configreference/system.webserver/httpcompression -
您是否尝试过使用本文中提到的 clear 元素?

I had a slightly similar problem before, too long ago to remember in detail. I think I resorted to making the changes directly to the ApplicationHost.config (%windir%\system32\inetsrv\config), but not an ideal solution.

Assume you've looked here
http://www.iis.net/configreference/system.webserver/httpcompression -
Have you tried using the clear element as mentioned in this post?

二智少女 2024-12-21 16:50:01

为此,在解锁 application.config 文件后,您还必须通过命令行设置特定配置。

1) 解锁 application.config 的 httpCompression 部分:

C:\Windows\System32\inetsrv\appcmd.exe unlock config /section:system.webServer/httpCompression

2) 让我们假设您想要处理动态 JSON 请求(例如 mimetype = application/json),您应该使用以下命令:

C:\Windows\System32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json',enabled='True']" /commit:apphost

3) 如果 JSON 请求是您的情况,您可能还需要处理 charset=utf -8 变化,由于某种原因,大多数情况下 IIS 都会返回给您:

C:\Windows\System32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json; charset=utf-8',enabled='True']" /commit:apphost

For this to work, after unlocking the application.config file you have to set the specific configuration via command line as well..

1) Unlock the httpCompression part of the application.config:

C:\Windows\System32\inetsrv\appcmd.exe unlock config /section:system.webServer/httpCompression

2) Lets suppose you want to handle dynamic JSON requests (e.g. mimetype = application/json), you should use this command:

C:\Windows\System32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json',enabled='True']" /commit:apphost

3) If JSON requests is your case, you might also want to handle the charset=utf-8 variation, which for some reason is what IIS gives you back in most cases:

C:\Windows\System32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json; charset=utf-8',enabled='True']" /commit:apphost
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文