I've been trying to implement HTTP compression on a few of my sites for some time now.
I've tried implementing HTTP compression using variations on the following two techniques:
From Application_BeginRequest in Global.asax
In both cases, it initially seems to work. But, as I navagate around the site, I quickly lose my CSS styling. And the brower reports a JS file contains invalid characters. And, at some point, the entire site turns entirely to jibberish.
I sure wish I knew what was happening here. Does anyone have any suggestion? Is it because these techniques only work on older versions of ASP.NET/IIS?
EDIT: I do not have access to IIS, and should not require it. With the latest iterations of ASP.NET and IIS, more and more control is being given to web.config without touching IIS. This should be fully supported without delving into IIS and, in fact, the two links above claim they are able to do just this. I just can't get it to work for me.
EDIT: On further inspection, using the code in the second link above (the HTTP module), I can see the module handler is being called for all file types on my site. This is clearly part of the problem. (Note that, in some cases, the entire page turns to garbage, which suggests other problems.) Can anyone suggest what determines which files are sent to the HTTP handler, or why the code at that link might work for someone else but not me?
While I may have had a few issues going on here, the following quote from Walkthrough: Creating and Registering a Custom HTTP Module seems to illuminate the problem:
As I was beginning to suspect, this is a change in ASP.NET 4.0 and IIS7. As I've mentioned several times, these are becoming more and more integrated. And the quote above suggests that HTTP modules now handle all files types served by IIS.
So that's why the older code doesn't work for me. And the fix appears to be to simply check the file type type from my handler.