class1.cs
来自「對c#初學者參考..為課題asp.net 2.0教材代碼」· CS 代码 · 共 60 行
CS
60 行
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.IO;
using System.IO.Compression;
namespace ClassLibrary1
{
public class Class1 : IHttpModule
{
#region IHttpModule Members
void IHttpModule.Dispose()
{
throw new Exception("The method or operation is not implemented.");
}
void IHttpModule.Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
//Get the Accept-Encoding HTTP header from the request.
//The requesting browser sends this header which we will use
// to determine if it supports compression, and if so, what type
// of compression algorithm it supports
string encodings = app.Request.Headers.Get("Accept-Encoding");
if (encodings == null)
return;
Stream s = app.Response.Filter;
encodings = encodings.ToLower();
if (encodings.Contains("gzip"))
{
app.Response.Filter = new GZipStream(s, CompressionMode.Compress);
app.Response.AppendHeader("Content-Encoding", "gzip");
app.Context.Trace.Warn("GZIP Compression on");
}
else
{
app.Response.Filter =
new DeflateStream(s, CompressionMode.Compress);
app.Response.AppendHeader("Content-Encoding", "deflate");
app.Context.Trace.Warn("Deflate Compression on");
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?