zoukankan      html  css  js  c++  java
  • .Net 高级 模拟事件模型

    第一步:创建一个类,并继承:IHttpModule

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Web;
     5 
     6 namespace ThreeLayerWebDemo._2019_7_14_Event
     7 {
     8     public class MyHttpModule : IHttpModule
     9     {
    10         public void Dispose()
    11         {
    12             
    13         }
    14 
    15         public void Init(HttpApplication context)
    16         {
    17             //注册第一个HttpApplication第一个事件
    18             context.BeginRequest += Context_BeginRequest;
    19         }
    20 
    21         private void Context_BeginRequest(object sender, EventArgs e)
    22         {
    23             var app = sender as HttpApplication;
    24             app.Response.Write("这是来自HttpModuel的代码<br/>");
    25         }
    26     }
    27 }

    第二步:配置web.config文件,分别在system.web和system.webserver下添加以下节点,type的值为:类的命名空间+类名

     1   <system.web>
     2     <httpModules>
     3       <add name="DemoModule" type="ThreeLayerWebDemo._2019_7_14_Event.MyHttpModule"/>
     4     </httpModules>
     5   </system.web>
     6 
     7   <system.webServer>
     8     <modules>
     9       <add name="DemoModule" type="ThreeLayerWebDemo._2019_7_14_Event.MyHttpModule"/>
    10     </modules>
    11   </system.webServer>
    ThreeLayerWebDemo._2019_7_14_Event.MyHttpModule:如下图

    测试

     

    搞定~

  • 相关阅读:
    模拟Promise
    js 重写concat
    js 重写 slice
    es6继承
    es5 简单继承
    iterator 和yield的关系
    iterator接口 ...和for of依赖的关键
    e.offsetX,Y到底是相对于谁
    mysql alter修改数据库表结构用法
    mysql修改表结构
  • 原文地址:https://www.cnblogs.com/chenyanbin/p/11182779.html
Copyright © 2011-2022 走看看