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

相关推荐
残*影2 天前
什么是MVC?
java·spring·mvc
保持学习ing2 天前
黑马Java面试笔记之框架篇(Spring、SpringMvc、Springboot)
java·笔记·spring·面试·mvc·mybatis·springboot
超级无敌永恒暴龙战士2 天前
SpringBoot-配置Spring MVC
spring boot·spring·mvc
二进制小甜豆3 天前
Spring MVC
java·后端·spring·mvc
Rocky4013 天前
SpringMVC的注解
spring boot·后端·mvc
杨-羊羊羊3 天前
MVVM、MVC的区别、什么是MVVM
mvc
添砖java_8576 天前
Spring MVC 框架
java·spring·mvc
代码老y6 天前
SpringMVC核心原理与前后端数据交互机制详解
java·mvc·交互
劲爽小猴头6 天前
企业级Spring MVC高级主题与实用技术讲解
java·spring boot·后端·spring·mvc
霖007 天前
详解GPU
人工智能·vscode·python·fpga开发·mvc·gpu算力