iis7 compress dynamic content from custom handler - iis-7

I am having trouble getting dynamic content coming from a custom handler to be compressed by IIS 7.
Our handler spits out json data (Content-Type: application/json; charset=utf-8) and responds to url that looks like: domain.com/example.mal/OperationName?Param1=Val1&Param2=Val2
In IIS 6, all we had to do was put the edit the MetaBase.xml and in the IIsCompressionScheme element make sure that the HcScriptFileExtensions attribute had the custom extension 'mal' included in it.
Static and Dynamic compression is turned out at the server and website level.
I can confirm that normal .aspx pages are compressed correctly.
The only content I cannot have compressed is the content coming from the custom handler.
I have tried the following configs with no success:
<handlers>
<add name="MyJsonService" verb="GET,POST" path="*.mal" type="Library.Web.HttpHandlers.MyJsonServiceHandlerFactory, Library.Web" />
</handlers>
<httpCompression>
<dynamicTypes>
<add mimeType="application/json" enabled="true" />
</dynamicTypes>
</httpCompression>
_
<httpCompression>
<dynamicTypes>
<add mimeType="application/*" enabled="true" />
</dynamicTypes>
</httpCompression>
_
<staticContent>
<mimeMap fileExtension=".mal" mimeType="application/json" />
</staticContent>
<httpCompression>
<dynamicTypes>
<add mimeType="application/*" enabled="true" />
</dynamicTypes>
</httpCompression>
Thanks in advance for the help.

looks like it is a bug in the IIS compression.
I needed to add the following line to the applicationHost.config file (under httpCompression ) instead of the web.config
<dynamicTypes>
<add mimeType="application/json; charset=utf-8" enabled="true" />
</dynamicTypes>
found some extra help from here: http://forums.iis.net/p/1162828/1925766.aspx

Related

IIS Compression setting for batch request mime type 'multipart/mixed'

I have a web api service that accepts batch requests from a web app. I have defined the mime type 'multipart/*' to be compressed in the web.config but the response is not compressed. I'm not sure why it is not working as normal single requests (not sent as a multipart/mixed are compressed fine).
<httpCompression>
<dynamicTypes>
<clear />
<add enabled="true" mimeType="text/*" />
<add enabled="true" mimeType="application/javascript" />
<add enabled="true" mimeType="application/json" />
<add enabled="true" mimeType="multipart/*" />
<add enabled="false" mimeType="*/*" />
</dynamicTypes>
<staticTypes>
<clear />
<add enabled="true" mimeType="text/*" />
<add enabled="true" mimeType="application/javascript" />
<add enabled="true" mimeType="application/json" />
<add enabled="true" mimeType="multipart/*" />
<add enabled="false" mimeType="*/*" />
</staticTypes>
</httpCompression>
The actual response mime type starts with 'multipart/mixed' but varies depending on the boundary id appended to it.
Content-Type:multipart/mixed; boundary="0bb00cbc-234a-4264-87dc-60109719e79f"
The request is sending up an Accepted-Encoding header so I don't think the problem is there I think it is something to do with IIS match the mime type.
Any ideas would be awesome!
Thanks,
Jon
I also ran into this, and was able to get around this by using this NuGet package:
https://www.nuget.org/packages/Microsoft.AspNet.WebApi.MessageHandlers.Compression/
This also supports the compression of the batch responses.
Info on how to use it is on the github page:
https://github.com/azzlack/Microsoft.AspNet.WebApi.MessageHandlers.Compression

Enable compression fontawesome-webfont.svg

I am always getting RED mark "enable compression for fontawesome-webfont.svg"
on https://developers.google.com/speed/pagespeed/insights/
Compressing resources with gzip or deflate can reduce the number of bytes sent over the network.
Enable compression for the following resources to reduce their transfer size by 175KiB (70% reduction).
Compressing /fonts/fontawesome-webfont.svg?v=4.0.3 could save 175KiB (70% reduction).
I already did IIS provided compression options:
Static files only
Dynamic application responses only
Both static files and dynamic application responses
By default, IIS doesn't map the MIME type for SVGs. You will have to update your Web.config to include the correct mappings for SVGs like so:
<system.webServer>
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
<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" />
<!-- HERE -->
<add mimeType="image/svg+xml" enabled="true" />
<add mimeType="application/font-woff" enabled="true" />
<add mimeType="application/x-font-ttf" enabled="true" />
<add mimeType="application/octet-stream" enabled="true" />
<!-- HERE -->
</staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true"/>
</system.webServer>
For more details on this, check out this answer. To test whether compression is working or not, use the Chrome Developer Tools and check the HTTP response header contains the following:
Content-Encoding: gzip

Moving <httpredirect> out of web.config in separate config file

We have many (more than 100) redirects in our web.config like
<configuration>
<system.webServer>
<httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found">
<add wildcard="/a" destination="/a/dfdf/default.htm" />
<add wildcard="/sad" destination="/aasd/dfdf/defsadault.htm" />
<add wildcard="/asdsaa" destination="/aasdas/dfasddf/default.htm" />
<add wildcard="/aasdsa" destination="/asdsaa/dfdf/defsdault.htm" />
<add wildcard="/aasd" destination="/adsa/dfdf/default.htm" />
..... more than 100
</httpRedirect>
</system.webServer>
</configuration>
Is there way we can have this section managed in separate web.config or any other best solution?
You can move some config elements into their own config file to reduce clutter in the web.config.
<configuration>
<system.webServer>
<httpRedirect configSource="httpRedirects.config" />
</system.webServer>
</configuration>
This is achieved by adding the configSource attribute as shown above.
And in your seperate httpRedirects.config
<httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found">
<add wildcard="/a" destination="/a/dfdf/default.htm" />
<add wildcard="/sad" destination="/aasd/dfdf/defsadault.htm" />
<add wildcard="/asdsaa" destination="/aasdas/dfasddf/default.htm" />
<add wildcard="/aasdsa" destination="/asdsaa/dfdf/defsdault.htm" />
<add wildcard="/aasd" destination="/adsa/dfdf/default.htm" />
</httpRedirect>
Note I have only tried this with other config elements.
You can store that in Separate Config file as shown here: SectionInformation.ConfigSource Property
In order to avoid cluttering the configuration file - web.config - it can be defined in a separate configuration file. That file can then be referenced from the web.config file as below:
<httpRedirect configSource="httpRedirects.config" />
The configSource attribute tells IIS configuration that the <httpRedirect> section is defined in a separate file httpRedirects.config.
EDIT:
Please make sure you have httpRedirect attribute set to enabled=true as the default value is false.
<httpRedirect enabled="true" configSource="httpRedirects.config" />

IIS 7 HttpCompression Not Working

I am using following web.config block to enable static and Dynamic Compression on IIS7, but its not compressing the response.(Verified it through Fiddler)
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
<dynamicTypes>
<add mimeType="text/css" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="*/*" enabled="true" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/css" enabled="true" />
<add mimeType="text/javascript" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="*/*" enabled="true" />
</staticTypes>
</httpCompression>
<staticContent>
<remove fileExtension=".js" />
<mimeMap fileExtension=".js" mimeType="application/x-javascript" />
</staticContent>
Yet it is not doing any compression. I had also check the server has static/dynamic compression installed.also tried this how-can-i-get-gzip-compression-in-iis7-working but not working for me. Can anyone help with something new?
I had trouble with getting it working by following snippets of advice on StackOverflow. Here's how I managed it.
First, ensure Dynamic Compression is installed as a feature of the Web Role. Normally, you get a warning in IIS Manager if the module is not installed, but you won't if you've set the web.config manually since it tricks the IIS UI logic.
I then removed all the web.config stuff (as in your question) and set it via the IIS Manager. I did this because on MSDN, an easily-missed comment says:
You can also add wildcard entries for the MIME types. However, you can
set MIME types for the web server level only. For example, to enable
static compression for all MIME types for the default website, first
add wildcard entries for the MIME types for the server level, and then
enable static compression for the default website.
Focus on:
However, you can set MIME types for the web server level only.
So I'm not sure whether all those filters and things really work in the web.config. Personally, it didn't for me - i.e. no Content-Encoding: gzip header.
After I took it all out I had to use IIS Manager, under IIS: Compression, to ensure it was set at the server level and then for the site, I had to remove the tick, apply it, tick it again and reapply it.
I ended up with just <urlCompression doDynamicCompression="true" /> in the web.config, which is a bit strange since I don't care for compressing URLs.
Whatever. I do now have Content-Encoding: gzip in the response headers for my site - so I assume its working.
Could you enable Failed Request Tracing, it should include information about what could be happening, it usually falls into a few buckets, 1) Permissions to generate the compressed file, 2) File is too small to require compression, 3) File is not being frequently enough so it is not being compressed, 4) mimetype issue
http://learn.iis.net/page.aspx/266/troubleshooting-failed-requests-using-tracing-in-iis7/

Gzip http compression problem on iis7

My web hosting provider is running IIS7 and I am having loads of trouble to get gzip compression to work properly. Host admins say compression is installed. I can confirm compression using some online checking services but not with others. PageSpeed Firefox add-on also says the site is uncompressed. I am personally sitting behind a Squid proxy but web.config settings should take care of proxy issue. Below is the relevant web.config snippet. Most of it is borrowed from various sites. Any thoughts?
<urlCompression doDynamicCompression="true" dynamicCompressionBeforeCache="true" doStaticCompression="true" />
<httpCompression cacheControlHeader="max-age=86400" noCompressionForHttp10="False" noCompressionForProxies="False" sendCacheHeaders="True" dynamicCompressionEnableCpuUsage="89" dynamicCompressionDisableCpuUsage="90" minFileSizeForComp="1" noCompressionForRange="False">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
This post is about 4 months old, but have you checked if dynamic compression is enabled in IIS? There's an article here on how to do it
http://blog.wassupy.com/2009/08/enabling-dynamic-http-compression-in.html
By default IIS it isn't enabled. Might be worth trying.
Try two this towards resolving this issue:
Try following the case standard for setting booleans in the web.config and use lower case rather than pascal casing.
Try connecting to the site on the server via IIS if your host allows this and check the compression section to see if it is locked.

Resources