Return 无论 applicationhost.config 如何,数据都不会压缩
Return data not compressing regardless of applicationhost.config
我在压缩来自 ASP.NET 应用程序的 return 数据时遇到问题。我将有一个测试方法 GetUserInfo,它将 return 数据。为了测试,我在此方法中只有以下内容才能获得足够大的结果集:
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" />
并且在同一个文件中, 包含:
<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 看到的有关 return headers 中内容的内容:
Content-Length→3991
Content-Type→application/json;字符集=utf-8
但我没有看到 Content-Type。我希望我在这里提供了足够的细节。
所以我编辑了位于 c:\windows\system32\inetsrv\config 的 hostApplication.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>
我在压缩来自 ASP.NET 应用程序的 return 数据时遇到问题。我将有一个测试方法 GetUserInfo,它将 return 数据。为了测试,我在此方法中只有以下内容才能获得足够大的结果集:
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" />
并且在同一个文件中,
<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 看到的有关 return headers 中内容的内容:
Content-Length→3991
Content-Type→application/json;字符集=utf-8
但我没有看到 Content-Type。我希望我在这里提供了足够的细节。
所以我编辑了位于 c:\windows\system32\inetsrv\config 的 hostApplication.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>