Running IIS 7
I'm trying to implement a custom Http Module, what I actually want is to implement gzip compression.
There seems to be a few ways to do this.
I am trying to do this by accessing the HttpApplication.BeginRequest event and add some code there that will use gzip.
I am using umbraco so I don't have a global.asax file so what I have got is a class file inside the app code folder of my website:
public class GzipHttpCompressionModule : IHttpModule
{
public GzipHttpCompressionModule()
{}
public void Dispose()
{}
public void Init(HttpApplication context)
{
context.BeginRequest +=
(new EventHandler(this.Application_BeginRequest));
}
private void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
HttpContext.Current.Response.AppendHeader("Content-encoding", "gzip");
HttpContext.Current.Response.Cache.VaryByHeaders["Accept-encoding"] = true;
}
}
Then inside my web-config file I register the module
<httpModules>
..
<!-- Register Custom Http Gzip Module -->
<add name="GzipHttpCompressionModule" type="GzipHttpCompressionModule"/>
..
</httpModules>
When I put a break point in Application_BeginRequest it never gets hit when I browse the website
Enable IIS7 gzip << The forth Answer down is the technique I am trying to implement.
Any ideas? why this isn't working?