C#使用IHttpModule接口修改http输出的方法
本文实例讲述了C#使用IHttpModule接口修改http输出的方法。分享给大家供大家参考。具体实现方法如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
//修改http输出先建个类这个类作为模块mould就要实现接口
namespace修改_HTTP_输出
{
publicclassMyMould:IHttpModule
//实现接口
{
//点击实现接口就会出来以下对应的属性和一个方法
publicvoidDispose()
//处理属性
{
thrownewNotImplementedException();
}
HttpContextc=null;
//定义个下面要用的当前请求对象变量初值为null
publicvoidInit(HttpApplicationcontext)
//初始化方法,HttpApplication是应用程序类
{
this.c=context.Context;
//1:给当前请求c赋值,Context获取当前请求的Http特定信息
context.BeginRequest+=newEventHandler(context_BeginRequest);
//当应用开始请求时;2:beginRequest是一个事件用委托定义事件
}
voidcontext_BeginRequest(objectsender,EventArgse)
//事件的处理方法
{
c.Response.Write("你的请求被我在mould中改了");
}
//上面的事件响应需要注册测在web.config
}
}
希望本文所述对大家的C#程序设计有所帮助。