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

相关推荐
喝养乐多长不高33 分钟前
Spring Web MVC基础理论和使用
java·前端·后端·spring·mvc·springmvc
bing_1582 天前
Spring MVC Controller 方法的返回类型有哪些?
java·spring·mvc
triticale2 天前
【Spring】Spring MVC笔记
笔记·spring·mvc
yuren_xia2 天前
Spring MVC中跨域问题处理
java·spring·mvc
bing_1582 天前
Spring MVC中Controller是如何把数据传递给View的?
java·spring·mvc
程序员buddha3 天前
【Spring Boot】Spring Boot + Thymeleaf搭建mvc项目
spring boot·后端·mvc
神秘的t3 天前
Spring Web MVC————入门(1)
java·spring·mvc
志存高远664 天前
MVC、MVP、MVVM三大架构区别
架构·mvc
bing_1585 天前
Spring MVC @CookieValue 注解怎么用?
java·spring·mvc
Aurora_NeAr5 天前
Spring MVC设计与实现
java·spring·mvc