新建一个类 ValidaterHttpModuleEvents继承管道接口 IHttpModule,代码如下

public class ValidaterHttpModuleEvents:IHttpModule
{
public void Dispose()
{ } public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
context.EndRequest += new EventHandler(context_EndRequest);
context.AuthorizeRequest += new EventHandler(context_AuthorizeRequest);
context.AcquireRequestState += new EventHandler(context_AcquireRequestState);
context.AuthenticateRequest += new EventHandler(context_AuthenticateRequest);
context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
context.PostRequestHandlerExecute += new EventHandler(context_PostRequestHandlerExecute);
context.ReleaseRequestState += new EventHandler(context_ReleaseRequestState);
context.UpdateRequestCache += new EventHandler(context_UpdateRequestCache);
context.ResolveRequestCache += new EventHandler(context_ResolveRequestCache);
context.PreSendRequestHeaders += new EventHandler(context_PreSendRequestHeaders);
context.PreSendRequestContent += new EventHandler(context_PreSendRequestContent);
} //
void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
application.Context.Response.Write("请求处理开始<br>");
} //
void context_AuthenticateRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
application.Context.Response.Write("封装请求身份验证<br>");
} //
void context_AuthorizeRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
application.Context.Response.Write("封装检查是否能利用以前缓存的输出页面处理请求的过程<br>");
} //4
void context_ResolveRequestCache(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
application.Context.Response.Write("从缓存中得到数据<br>");
}
//5加载初始化Session
void context_AcquireRequestState(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
application.Context.Response.Write("封装坚持是否能利用以前缓存的输出页面处理请求<br>");
}
//
void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
application.Context.Response.Write("Http请求进入HttpHandler之前触发<br>");
} //
void context_PostRequestHandlerExecute(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
application.Context.Response.Write("在Http请求进入HttpHandler之后触发<br>");
} //
void context_ReleaseRequestState(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
application.Context.Response.Write("存储Session状态时触发<br>");
} //
void context_UpdateRequestCache(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
application.Context.Response.Write("更新缓存信息时触发<br>");
} //
void context_EndRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
application.Context.Response.Write("Http请求处理完成<br>");
} //
void context_PreSendRequestHeaders(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
application.Context.Response.Write("在向客户端发送Header之前触发<br>");
} //
void context_PreSendRequestContent(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
application.Context.Response.Write("在向客户端发送内容之前触发<br>");
}

  新建一个aspx页面,在Page_Load事件写上

   Response.Write("<br/><br/>来自Default.aspx页面<br/>");

  最后,在配置文件中加上如下代码

  <httpModules>
    <add name="MyHttpModule" type="HttpModuleTest.ValidaterHttpModuleEvents,HttpModuleTest"/>
  </httpModules>

  type中的“HttpModuleTest”表示最基本的命名空间,ValidaterHttpModuleEvents表示自己的HttpModule名称。

  运行结果如下图所示

  

最新文章

  1. java动态编译笔记
  2. Angularjs Controller间通信的几种方法
  3. DevExpress应用案例--语音识别器Dual Writer
  4. android技巧(四)数据库跨版本升级写法
  5. IOS开发UI基础UISlide属性
  6. 如何判断两个String是否是Anagrams_java实现
  7. Mahout推荐算法基础
  8. 如何修改WAMP数据库上传文件的大小及上传时间限制
  9. 初学cocos2dx-3.x之使用Scale9Sprite时的配置问题
  10. Bash的脚本参数
  11. Android给listview的item设定高度
  12. 刨根究底字符编码之十二——UTF-8究竟是怎么编码的
  13. Linux 多个JDK的版本 脚本切换
  14. vs2015 制作安装包额外需要安装的软件VSI_bundle
  15. vue2.0实现过滤
  16. tomcat9配置https
  17. spring-AOP(面向切面编程)-注解方式配置
  18. python设计模式第八天【装饰器模式】
  19. Heaven of Imaginary(PKUSC2018)
  20. js实例分析JavaScript中的事件委托和事件绑定

热门文章

  1. javascript获取iframe框架中页面document对象,获取子页面里面的内容,iframe获取父页面的元素,
  2. ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室(十一) 代码重构使用反射工厂解耦
  3. Silverlight管理系统源代码(SilverlightOAFlame开发框架主要提供二次开发)
  4. mysql 的 infobright 数据库的 mediumblob 显示不了数据
  5. .NET:序列化和反序列化
  6. 黄聪:PHP页面跳转如何实现延时跳转
  7. SELECT INTO FROM 与 INSERT INTO SELECT区别鉴赏
  8. [MySQL] SQL_ERROR 1032解决办法
  9. 112、两个Activity切换黑屏问题
  10. quartus II PIN脚相关之一