MVC之 IHttpModule管道模型

csharp 复制代码
system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules>
      <add name="CustomHttpModule" type="WebApplication6.Utility.CustomHttpModule,WebApplication6"/>
    </modules>
  </system.webServer>
csharp 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApplication6.Utility
{
    public class CustomHttpModule : IHttpModule
    {
        public void Dispose()
        {
            throw new NotImplementedException();
        }
        public event EventHandler EventHandler;
        public void Init(HttpApplication application)
        {
            //application.BeginRequest += (s, e) =>
            //{
            //    if (this.EventHandler != null)
            //        this.EventHandler.Invoke(application, e);
            //};
            application.AcquireRequestState += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "AcquireRequestState        "));
            application.AuthenticateRequest += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "AuthenticateRequest        "));
        }
    }
}
注册HttpModule

在注册我们自己编写的 Http Module 之前,先来看看Asp.Net中已经有的HttpModule。与 Http Handler类似,我们需要打开机器上

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config

相关推荐
好学且牛逼的马3 天前
从“Servlet汪洋”到“响应式时代”:Spring MVC 1.x到5.x演进全记录与核心知识点详解
spring·servlet·mvc
知识即是力量ol6 天前
口语八股——Spring 面试实战指南(二):事务管理篇、Spring MVC 篇、Spring Boot 篇、Bean生命周期篇
spring·面试·mvc·springboot·八股·事务管理·bean生命周期
weixin_421994786 天前
MVC 模式初探
mvc·.net·.netcore
亓才孓7 天前
[Spring MVC]BindingResult
java·spring·mvc
小钻风33667 天前
Spring MVC拦截器的快速应用
java·spring·mvc
MSTcheng.15 天前
探索昇腾底层逻辑:从ops-nn视角解读aclnn两阶段设计理念
mvc
勤奋的小王同学~16 天前
SpringMVC
java·spring·mvc
IT 行者18 天前
Spring MVC 慎用@InitBinder,谨防内存泄漏
java·spring·mvc
树码小子18 天前
SpringMVC(6) :阶段总结
spring·mvc