IIS 8.5中的压缩未成功,说明ALREADY_CONTENT_ENCODING [英] Compression in IIS 8.5 not successful, stating ALREADY_CONTENT_ENCODING

查看:111
本文介绍了IIS 8.5中的压缩未成功,说明ALREADY_CONTENT_ENCODING的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调试为什么我的页面没有按照YSLOW进行GZIP处理或缩小的问题。我最终在服务器上启用了失败请求日志,并且能够看到未压缩的失败原因,它认为它已经被压缩。

I am trying to debug the issue of why my pages are not being GZIP'ed or deflated according to YSLOW. I ended up enabling Failed Request Logs on the server and was able to see the failed reason of why it is not compressing, it thinks it is already compressed.

DYNAMIC_COMPRESSION_NOT_SUCCESS Reason="ALREADY_CONTENT_ENCODING"

我已在IIS中启用了动态和静态压缩,我还更改了web.config文件,使其包含以下内容。

I have enabled dynamic and static compression in IIS, I have also changed the web.config file to include the following.

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
  <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" />
  <dynamicTypes>
    <add mimeType="text/*" enabled="true" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/x-javascript" enabled="true" />
    <add mimeType="application/json" enabled="true" />
    <add mimeType="*/*" enabled="false" />
  </dynamicTypes>
  <staticTypes>
    <add mimeType="text/*" enabled="true" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/x-javascript" enabled="true" />
    <add mimeType="application/atom+xml" enabled="true" />
    <add mimeType="application/xaml+xml" enabled="true" />
    <add mimeType="*/*" enabled="false" />
  </staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true"/>

此外,在我的aspx页面上,我有一种方法(在页面加载时)在每个页面之前调用运行gzip压缩(这可能是导致错误的原因)。

In addition on my aspx page I have a method I call before every page (on page load) to run gzip compression (this might be why it is causing the error).

这是我从页面加载中调用方法的方式

This is how I call the method from the page load

//compress page
Compression.GZipEncodePage();

这是压缩页面的方法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace InitialDataEntry
{
    public static class Compression
    {
        /// <summary>
        /// Sets up the current page or handler to use GZip through a Response.Filter
        /// IMPORTANT:  
        /// You have to call this method before any output is generated!
        /// </summary>
        public static void GZipEncodePage()
        {
            HttpResponse Response = HttpContext.Current.Response;
        if (IsGZipSupported())
        {
            string AcceptEncoding = HttpContext.Current.Request.Headers["Accept-Encoding"];
            if (AcceptEncoding.Contains("deflate"))
            {
                Response.Filter = new System.IO.Compression.DeflateStream(Response.Filter,
                                           System.IO.Compression.CompressionMode.Compress);
                Response.AppendHeader("Content-Encoding", "deflate");
            }
            else
            {
                Response.Filter = new System.IO.Compression.GZipStream(Response.Filter,
                                          System.IO.Compression.CompressionMode.Compress);
                Response.AppendHeader("Content-Encoding", "gzip");
            }
        }

        // Allow proxy servers to cache encoded and unencoded versions separately
        Response.AppendHeader("Vary", "Content-Encoding");
    }

    /// <summary>
    /// Determines if GZip is supported
    /// </summary>
    /// <returns></returns>
    public static bool IsGZipSupported()
    {
        string AcceptEncoding = HttpContext.Current.Request.Headers["Accept-Encoding"];
        string IsPartial = HttpContext.Current.Request.Headers["x-microsoftajax"];

        if (!string.IsNullOrEmpty(AcceptEncoding) &&
             AcceptEncoding.Contains("gzip") || AcceptEncoding.Contains("deflate"))

            //Just checking to see if this is a partial page update
            if (string.Compare("Delta=true", IsPartial, true) == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        else
        {
            return false;
        }
    }
}
}

此过去一直是这样工作的,但不确定何时停止,但是我的用户意识到了问题,因为页面的大小过大,而以前的500k现在变成了2mb!

This used to work by the way, but not sure when it stopped, however my users realized the issue as the pages got bloated in size and what used to be 500k is now 2mb!

任何帮助将不胜感激。

谢谢

推荐答案

我们在Windows 2012 R2服务器上遇到了类似的问题;以下步骤解决了我们的问题:

We had a similar issue on Windows 2012 R2 server; following below steps solved our problem:


  1. 选择一个IIS站点,然后转到配置编辑器。

  2. 选择 system.web / caching / outputCache部分,然后将 omitVaryStar属性设置为 true

  3. 选择system.webServer,然后选择httpCompression。

  4. 将 staticCompressionIgnoreHitFrequency属性设置为 true

  5. iisreset

  1. Select an IIS site, and go to Configuration Editor.
  2. Select "system.web/caching/outputCache" section, then set the "omitVaryStar" property to "true"
  3. Select system.webServer, and then select httpCompression.
  4. set "staticCompressionIgnoreHitFrequency" property to "true"
  5. iisreset

这篇关于IIS 8.5中的压缩未成功,说明ALREADY_CONTENT_ENCODING的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆