每当我尝试运行我的项目时,都会收到以下错误:
Error 19 Type 'CompressionModule' does not inherit from System.Web.IHttpHandler'.
这是我的模块代码
using System;
using System.IO.Compression;
using System.Web;
namespace SWMS
{
public class CompressionModule : IHttpModule
{
void IHttpModule.Dispose()
{
}
void IHttpModule.Init(HttpApplication context)
{
context.PreRequestHandlerExecute += new EventHandler(context_PostReleaseRequestState);
}
void context_PostReleaseRequestState(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
if (app.Context.CurrentHandler is System.Web.UI.Page && app.Request["HTTP_X_MICROSOFTAJAX"] == null)
{
if (IsEncodingAccepted(GZIP))
{
app.Response.Filter = new GZipStream(app.Response.Filter, CompressionMode.Compress);
SetEncoding(GZIP);
}
else if (IsEncodingAccepted(DEFLATE))
{
app.Response.Filter = new DeflateStream(app.Response.Filter, CompressionMode.Compress);
SetEncoding(DEFLATE);
}
}
}
private const string GZIP = "gzip";
private const string DEFLATE = "deflate";
private static bool IsEncodingAccepted(string encoding)
{
HttpContext context = HttpContext.Current;
return context.Request.Headers["Accept-encoding"] != null && context.Request.Headers["Accept-encoding"].Contains(encoding);
}
private static void SetEncoding(string encoding)
{
HttpContext.Current.Response.AppendHeader("Content-encoding", encoding);
}
}
}
我使用以下代码注册我的模块
<system.web>
<httpModules>
<add name="compression" type="SWMS.CompressionModule, SWMS "/>
</httpModules>
</system.web>
任何人都可以帮我理解我做错了什么?