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

相关推荐
Cloud-Future1 天前
Spring MVC 处理请求的流程
java·spring·mvc
optimistic_chen3 天前
【Java EE进阶 --- SpringBoot】Spring IoC
spring boot·后端·spring·java-ee·mvc·loc
wuk9983 天前
在Spring MVC中使用查询字符串与参数
java·spring·mvc
原来是好奇心4 天前
深入剖析Spring Boot中Spring MVC的请求处理流程
spring boot·spring·mvc
xkroy4 天前
创建Spring MVC和注解
学习·spring·mvc
期待のcode4 天前
SpringMVC的请求接收与结果响应
java·后端·spring·mvc
Pure03195 天前
Spring MVC BOOT 中体现的设计模式
spring·设计模式·mvc
The Sheep 20235 天前
.NetCore MVC
mvc·.netcore
YDS8295 天前
SpringMVC —— Spring集成web环境和SpringMVC快速入门
java·spring·mvc·springmvc
xkroy5 天前
Sping Web MVC入门
mvc