I have found numerous articles and blog posts which go into detail of the various ways this can be accomplished. Some look involved with custom coding, and are (right at this moment) not what I am wanting (I want a configuration solution). Some of these posts (SO included) share how to do this through configuration over custom coding, but to no success on my end. Here is my attempt so far. Have I overlooked anything? Is my Web.config
to blame, or is there something else I must specify on my request?
Additional Details
- I am running IIS Express 8 (product version: 8.5.9748.0) on my localhost
- Windows 8.1
- I am making requests with Fiddler - but the same response occurs with ajax calls (AngularJS)
Fiddler Get Headers
User-Agent: Fiddler
Host: localhost:5293
Accept: application/json; charset=utf-8, application/json Accept-Encoding: gzip
JS Request (AngularJS)
$http.get('localhost:5293/api/Whatever', {
headers: {
'Accept': 'application/json; charset=utf-8, application/json',
'Accept-Encoding': 'gzip'
}
});
Problem
My response is always
application/json; charset=utf-8
Efforts
- I have enabled Dynamic Content Compression and Static Content Compression on Windows features under IIS (Turn Windows features on or off)
- Reset Windows Process Activation Service
Run following commands, and verified the results as such
appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json',enabled='True']" /commit:apphost appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json; charset=utf-8',enabled='True']" /commit:apphost
Verify Command:
appcmd.exe list config -section:system.webServer/httpCompression
Verify Response:
<system.webServer>
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="application/atom+xml" enabled="true" />
<add mimeType="application/xaml+xml" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="*/*" enabled="false" />
<add mimeType="application/json" enabled="true" />
<add mimeType="application/json; charset=utf-8" enabled="true" />
</dynamicTypes>
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
</httpCompression>
</system.webServer>
I have placed this exact configuration in my Web.config
file under the <system.webServer>
node, and still no luck...
Web Api Controller Method
public JsonResult Get()
{
return new JsonResult
{
Data = "foo",
ContentType = "application/json; charset=utf-8",
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
}