I am having issues with compressing data returned from my ASP.NET application. I'll have a test method GetUserInfo that will return data. To test, I only have the following in this method to have a big enough result set:
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;
In applicationhost.config (in IISExpress folder), I have the following:
<section name="httpCompression" overrideModeDefault="Allow" />
And in this same file, <httpCompression...> contains:
<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>
Below is what I see from PostMan regarding Content in the return headers:
Content-Length →3991
Content-Type →application/json; charset=utf-8
But I'm not seeing Content-Type. I hope I included enough details here.
So I edited the hostApplication.config file located in: c:\\windows\\system32\\inetsrv\\config. I think I was looking at the wrong one in SysWOW64. But I added the following, and it worked.
<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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.