views:

386

answers:

4

My pages are automatically being compressed by IIS7 with GZIP.

That is great... but, for one particular page, I need to stream it to the user, using Response.Flush() when needed. But when the output is being compressed, the IIS server seems to collect all my output until the page is done before compressing and sending it to the client. That nullifies my attempt to Flush the content out to the user.

Is there a way that I can have this one page opt out of the compression?

One possible option

I've determined that if I manually set the content type to one that does not match the IIS configuration at c:\windows\system32\inetsrv\config\applicationhost.config, then IIS will not compress it. Eg. Response.ContentType = "x-text/html". This works okay with IE8, as it falls back to display the HTML. But Firefox will ask the user what to do with the unknown file type.

This could work, if there was another Mime Type I could use that browsers would accept as HTML, that is not matched in the applicationhost.config. For reference, these are the mime types that will be compressed:

   <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" />

Others options?

Are there other options to opt out of compression?

A: 

I know of no way of a page to disable itself programmatically during the request. However you can workaround the compression and send some extra padding garbage, enough for gzip to process a new block. Your padding data should be as random as possible so it doesn't get too compressed, filling the deflate buffer faster.

The actual amount of data to send depends on the compression module's configurations.

Miguel Ventura
+1  A: 

It may not be possible to disable compression for a certain page, but you can for a directory.

This describes how to disable static compression, but it may work for dynamic compression: (From http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/502ef631-3695-4616-b268-cbe7cf1351ce.mspx?mfr=true)

To disable static compression for only a single directory, first enable global static compression (if it is disabled) and then disable static compression at that directory. For example, to enable static compression for a directory at http://www.contoso.com/Home/StyleSheets, perform the following steps:

  1. Disable global static compression by executing the following command at a command prompt:

adsutil set w3svc/filters/compression/parameters/HcDoStaticCompression true

2.Enable static compression at this directory by executing the following command at a command prompt:

adsutil set w3svc/1/root/Home/StyleSheets/DoStaticCompression false

Nicolas
A: 

Not sure I like this but maybe worth mentioning: http://stackoverflow.com/questions/824704/disable-gzip-compression-for-ie6-clients

MK
This is the most promising approach I've seen so far. Thanks!
Glen Little
A: 

You could use a custom made compression module, like this one: http://madskristensen.net/post/HTTP-compression-of-WebResourceaxd-and-pages-in-ASPNET.aspx

Using such it should be easy to customize which files to include/exclude.

asgerhallas