新建一个类 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名称。

  运行结果如下图所示

  

HttpModule的一些初步认识的更多相关文章

  1. ASP.NET底层与各个组件的初步认识与理解 (转载)

    ASP.NET底层的初步认识与理解   最近在国外的网站乱走一通,发现一些比较好的文章,收集整理加于自己的理解,作为笔记形式记录下来,让以后自己有个回忆. ASP.NET是一个非常强大的构建Web应用 ...

  2. Git使用总结 Asp.net生命周期与Http协议 托管代码与非托管代码的区别 通过IEnumerable接口遍历数据 依赖注入与控制反转 C#多线程——优先级 AutoFac容器初步 C#特性详解 C#特性详解 WPF 可触摸移动的ScrollViewer控件 .NET(C#)能开发出什么样的APP?盘点那些通过Smobiler开发的移动应用

    一,原理 首先,我们要明白Git是什么,它是一个管理工具或软件,用来管理什么的呢?当然是在软件开发过程中管理软件或者文件的不同版本的工具,一些作家也可以用这个管理自己创作的文本文件,由Linus开发的 ...

  3. 移动端之Android开发的几种方式的初步体验

    目前越来越多的移动端混合开发方式,下面列举的大多数我都略微的尝试过,就初步的认识写个简单的心得: 开发方式 开发环境 是否需要AndroidSDK 支持跨平台 开发语言&技能 MUI Win+ ...

  4. CSharpGL(29)初步封装Texture和Framebuffer

    +BIT祝威+悄悄在此留下版了个权的信息说: CSharpGL(29)初步封装Texture和Framebuffer +BIT祝威+悄悄在此留下版了个权的信息说: Texture和Framebuffe ...

  5. Android自定义View初步

    经过上一篇的介绍,大家对于自定义View一定有了一定的认识,接下来我们就以实现一个图片下显示文字的自定义View来练习一下.废话不多说,下面进入我们的正题,首先看一下我们的思路,1.我们需要通过在va ...

  6. 初步认识Node 之Node为何物

    很多人即便是在使用了Node之后也不知道它到底是什么,阅读完本文你应该会有一个初步的.具体的概念了.    Node的目标 提供一种简单的构建可伸缩网络程序的方法.那么,什么是可伸缩网络程序呢?可伸缩 ...

  7. [入门级] 基于 visual studio 2010 mvc4 的图书管理系统开发初步 (二)

    [入门级] 基于 visual studio 2010 mvc4 的图书管理系统开发初步 (二) Date  周六 10 一月 2015 By 钟谢伟 Category website develop ...

  8. ASP.NET使用HttpModule压缩并删除空白Html请求

    当我们压缩我的Response后再传到Client端时,可以明显节省宽带. 提升Site的性能. 现在的浏览器大部分都支持Gzip,Deflate压缩. 同时我们还可以删除一些空白段,空行,注释等以使 ...

  9. [转]HttpModule的认识

    HttpModule是向实现类提供模块初始化和处置事件.当一个HTTP请求到达HttpModule时,整个ASP.NET Framework系统还并没有对这个HTTP请求做任何处理,也就是说此时对于H ...

随机推荐

  1. NetCFSvcUtil.exe and Windows 7

    NetCFSvcUtil.exe is the analogous of Svcutil.exe but for devices. You can use it to generate a WCF c ...

  2. Java入门教程总目录

    Java入门教程总目录 持续更新中... 1.Java常识汇总 2.Java框架对比 3.Java技术路线 4.Java编码规范 5.Java环境变量配置 6.枚举 7.操作符 12.定时任务

  3. bzoj2518: [Shoi2010]滚动的正四面体

    Description 正四面体总共有4个面,每个面都是一个正三角形.现在把它的一个面标记上字母A,如图 3中所示,A标记在底面上: 于是,这个正四面体的滚动过程就可以用一个只包含“L”“R”“B”的 ...

  4. Oracle存储过程 输出参数赋值异常:“Oracle.DataAccess.Types.OracleString”的类型初始值设定项引发异常。

    场景: 写了一个有返回参数的存储过程,在个另开发人员机器上都正常.其它机器报如题错误.让人郁闷的是,所有调用方都是客户端,根本不存在网上众贴所说的版本不一致问题. 分析: 虽然网上的帖子没有根本解决问 ...

  5. IOS跳转设置页面及其他各种跳转页面设置

    转载来源 CocoaChina 跳到更多设置界面 除了跳到WiFi设置界面,能不能跳到其他的设置界面呢?比如:定位服务.FaceTime.音乐等等.都是可以的,一起来看看如何实现的! 定位服务 定位服 ...

  6. iOS开发中的4种数据持久化方式【一、属性列表与归档解档】

    iOS中的永久存储,也就是在关机重新启动设备,或者关闭应用时,不会丢失数据.在实际开发应用时,往往需要持久存储数据的,这样用户才能在对应用进行操作后,再次启动能看到自己更改的结果与痕迹.ios开发中, ...

  7. Extract QQ from iPhone and analyze it

    QQ is one of the most popular chat App in the world. Now let me show you how to extract QQ from iPho ...

  8. HTML4.01和XHTML1.0和XHTML1.1的一些区别

    接触web前端以来,一直使用的都是html5,因此一直没搞明白HTML4.01和XHTML1.0和XHTML1.1之间的区别,今天在看<精通CSS>一书,有简单介绍这几个,在这儿记录下. ...

  9. findstr 命令

    body { font-family: Bitstream Vera Sans Mono; font-size: 11pt; line-height: 1.5; } html, body { colo ...

  10. EMR,电子病历(Electronic Medical Record)

    电子病历 电子病历(EMR,Electronic Medical Record),也叫计算机化的病案系统或称基于计算机的病人记录(CPR,Computer-Based Patient Record). ...