views:

1371

answers:

4

For now I'm stuck with IIS6 for ASP.NET-MVC (as in I cant upgrade to Server 2008 yet). It doesnt seem to know that my RESTful URLS are dynamic files and isn't compressing them.

All my old .aspx files are compressed (as seen in Fiddler), but not the '/products/1001' type URLS.

Is there any way to get IIS6 to compress my ActionResults in IIS6 without using something like an ActionFilter for compression.

I'm assuming IIS7 is clever enough to know they're dynamic right.

Bonus points if you can tell me how IIS6 even knows which files are dynamic in the first place!

A: 

You need to add "." to your HcScriptFileExtensions metabase attribute.

ssg
isnt that just going to grind everything to a halt - with it compressing JPEGS and SWFs and everything in between ?
Simon_Weaver
"." is not ".*"
ssg
+2  A: 

As HTTP compression for ASP.NET usually has been implemented using HttpModules since version 1.0, and HttpModules still belong to the ASP.NET request pipeline used by the MVC framework, you can still use a HttpModule to inject a GZIP or deflate response filter.

Here you can find a very nice, open-source, ready to ship implementation: HttpCompress by Ben Lowery (download at Google Code)

You just have to add a reference to the DLL, and add a few lines to your web.config. It already handles very exotic and rare cases and exceptions. You can add exclusions to your web.config, not based on file extensions (like in IIS6), but on mime type, which is probably exactly what you need.

I should add that I have actually running a ASP.NET MVC website on IIS6 using this library, so I can confirm that this works in practice.

markus
so am i better off using something like this and excluding files I dont want - such as JPEG, SWF ? another alternative is in another question I asked : http://stackoverflow.com/questions/649409/can-you-apply-an-actionfilter-in-asp-net-mvc-on-every-action - and use this for CompressFilter
Simon_Weaver
I would go with the HttpModule, because it keeps your controllers clean, and it will be applied to every requests (except for excluded mime types like you mentioned), e. g. CSS files, static HTML etc., not only requests handled by your controller actions.
markus
A: 

In a web config you should register StaticFileHandler and HTTP Module

<add verb="GET,HEAD,POST" path="*" type="[Web.Front.Modules].StaticFileHandler"/>
<add name="HttpCompressionModule" type="[Web.Front.Modules].HttpCompressionModule"/>

Source code you will find here

But do not forget to turn on compression on IIS

omoto
A: 

Here's one option that seems to be working for me with MVC and IIS 6 using wildcard mappings and extensionless urls:

  1. set dynamic and static compression globally using the admin tool
  2. edit the metabase.xml so that HcScriptFileExtensions is blank in the CompressionSchemes. This will try to compress everything (including jpgs and gifs).
  3. Turn off dynamic compression at the folder level using the DoDynamicCompression = "false" property. This assumes all your static content is one directory.
  4. Add the static file extensions you do want compressed (css, js, etc) in the HcFileExtensions property.

This is a workaround, but I'm stuck with Server 2003 and IIS 6 for the moment.

Jimtronic