无论applicationhost.config如何,都返回不压缩的数据

时间:2016-09-16 16:11:22

标签: asp.net iis compression gzip

我在压缩从ASP.NET应用程序返回的数据时遇到问题。我将有一个将返回数据的测试方法GetUserInfo。为了测试,我在此方法中只有以下内容才能拥有足够大的结果集:

UserModel users = new List<UserModel>();

for (int i = 0; i < 2000; i++)
{
    UserModel _usr = new UserModel();
    _usr = new UserModel();
    _usr.Id = i.ToString();
    _usr.Number = "Abc" + i;
    _usr.Name = i + "Abc";
    users.Add(_usr);
    _user = null;
}

HttpResponseMessage json = Request.CreateResponse(HttpStatusCode.OK, users);

return json;

在applicationhost.config(在IISExpress文件夹中)中,我有以下内容:

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

在同一个文件中,&lt; httpCompression ...&gt;包含:

    <httpCompression directory="%TEMP%\iisexpress\IIS Temporary Compressed Files">
        <scheme name="gzip" dll="C:\Windows\System32\inetsrv\gzip.dll" />
        <dynamicTypes>
            <add mimeType="*/*" enabled="true"/>
            <add mimeType="text/*" enabled="true"/>
            <add mimeType="message/*" enabled="true"/>
            <add mimeType="application/javascript" enabled="true"/>
            <add mimeType="application/json" enabled="true"/>
            <add mimeType="application/json; charset=utf-8" enabled="true" />
            <add mimeType="application/xml; charset=utf-8" enabled="true" />
            <add mimeType="*/*" enabled="false"/>
        </dynamicTypes>
        <staticTypes>
          <add mimeType="*/*" enabled="true"/>
          <add mimeType="text/*" enabled="true"/>
          <add mimeType="message/*" enabled="true"/>
          <add mimeType="application/javascript" enabled="true"/>
          <add mimeType="application/json" enabled="true"/>
          <add mimeType="application/json; charset=utf-8" enabled="true" />
          <add mimeType="application/xml; charset=utf-8" enabled="true" />
          <add mimeType="*/*" enabled="false"/>
        </staticTypes>
    </httpCompression>

以下是我在PostMan中看到的返回标题中的内容:

Content-Length→3991

Content-Type→application / json;字符集= UTF-8

但我没有看到Content-Type。我希望我在这里提供足够的细节。

1 个答案:

答案 0 :(得分:0)

所以我编辑了位于以下位置的hostApplication.config文件:c:\ windows \ system32 \ inetsrv \ config。我想我在SysWOW64中看错了。但我添加了以下内容,并且有效。

    <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
        <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
        <staticTypes>
            <add mimeType="*/*" enabled="true"/>
            <add mimeType="text/*" enabled="true"/>
            <add mimeType="message/*" enabled="true"/>
            <add mimeType="application/javascript" enabled="true"/>
            <add mimeType="application/json" enabled="true"/>
            <add mimeType="application/json; charset=utf-8" enabled="true" />
            <add mimeType="application/xml; charset=utf-8" enabled="true" />
        </staticTypes>
        <dynamicTypes>
              <add mimeType="*/*" enabled="true"/>
              <add mimeType="text/*" enabled="true"/>
              <add mimeType="message/*" enabled="true"/>
              <add mimeType="application/javascript" enabled="true"/>
              <add mimeType="application/json" enabled="true"/>
              <add mimeType="application/json; charset=utf-8" enabled="true" />
              <add mimeType="application/xml; charset=utf-8" enabled="true" />
        </dynamicTypes>
    </httpCompression>