ASP.net Custom Http Modules
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?
The <httpModules>
tag inside the <system.web>
tag is only used by old IIS versions (<=6) or when you use the classic mode (not recommended). Use <modules>
in <system.webServer>
instead.
More information here: http://www.byteblocks.com/post/2010/09/16/HttpModule-Not-Working-In-IIS7.aspx
链接地址: http://www.djcxy.com/p/43788.html上一篇: >逐个加载并显示
下一篇: ASP.net自定义Http模块