新建一个类 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. 20151216Repeater

    Repeater 用法:.绑定数据源 Repeater1.DataSource = context.Info; Repeater1.DataBind(); .造项模版: 头模版:HeaderTempl ...

  2. CentOS 7 httpd服务的安装、配置

    关于linux   httpd的搭建和配置都需要基于yum源 1:安装httpd yum linstall httpd -y 2:进入html文件 cd /var/www/html 讲已经编辑的htm ...

  3. IOCP简单实现

    本人工作是服务端性能测试,因工作需要开发机器人框架,选用底层的时候看到网上满大街的IOCP介绍,还有说IOCP比WSAAsyncSelect复杂等等,所以只好转WSAAsyncSelect实现. 因并 ...

  4. mysql 语法总结

    设置SQL语句所用的字符编码:set names UTF8; 判断指定的数据库是否存在:DROP DATABASE IF EXISTS  库; 开始使用指定的数据库:USE 库; 创建数据库CREAT ...

  5. 每天一个 Linux 命令(7):mv命令

    mv命令是move的缩写,可以用来移动文件或者将文件改名(move (rename) files),是Linux系统下常用的命令,经常用来备份文件或者目录. 1.命令格式: mv [选项] 源文件或目 ...

  6. [ActionScript 3.0] AS3.0 烟雾粒子效果

    package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; ...

  7. Visual Studio Enterprise 2015下载 Update3

    Visual Studio 2015 是一个丰富的集成开发环境,可用于创建出色的 Windows.Android 和 iOS 应用程序以及新式 Web 应用程序和云服务. 1.适用于各种规模和复杂程度 ...

  8. my first article

    BLOG:  http://codetask.org GIT:  http://git.oschina.net/codetimer

  9. EXT学习之——Ext下拉框绑定无效的问题

    1.保证store定义是否在combobox前面 2.有没写  .load 3.有没赋值  xxstore:xxstore 具体看详细步骤 http://www.cnblogs.com/wdw3121 ...

  10. 在本地主机上powershell中连接远程主机执行vbs脚本,得到执行结果(2008版及以上)

    在桌面版的主机上远程管理服务器版主机,在本地powershell中连接远程主机执行vbs脚本,得到执行结果. 执行步骤: 1.将本地主机上的Hyper.vbs复制到远程连接主机上.例如,本地vbs脚本 ...