我正在實現HttpModule來壓縮請求。 下面是HTTP模塊的codee:HttpModule不攔截IIS 5.1中的js和css文件
public class Global : IHttpModule
{
public void Init(HttpApplication app)
{
app.PostReleaseRequestState += new EventHandler(app_PostReleaseRequestState);
}
void app_PostReleaseRequestState(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
HttpContext context = app.Context;
string acceptEncoding = context.Request.Headers["Accept-Encoding"];
// If gzip is supported then gzip it else if deflate compression is supported then compress in that technique.
if (acceptEncoding.Contains("gzip"))
{
// Compress and set Content-Encoding header for the browser to indicate that the document is zipped.
context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
context.Response.AppendHeader("Content-Encoding", "gzip");
}
else if (acceptEncoding.Contains("deflate"))
{
// Compress and set Content-Encoding header for the browser to indicate that the document is zipped.
context.Response.Filter = new DeflateStream(context.Response.Filter, CompressionMode.Compress);
context.Response.AppendHeader("Content-Encoding", "deflate");
}
}
它能夠攔截和壓縮JS和CSS在開發Web服務器,但是當我從IIS 5.1 運行它,它是不能夠壓縮JS和CSS文件。 請幫忙。
但它能攔截web開發者2008的開發web服務器。 – 2011-02-14 14:28:13