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

相关推荐
A尘埃1 天前
MVC应用单元测试以及请求参数的验证
单元测试·mvc
人类群星闪耀时1 天前
ASP.NET MVC 迅速集成 SignalR
后端·asp.net·mvc
F元凯2 天前
Spring MVC的异步模式(ResponseBodyEmitter、SseEmitter、StreamingResponseBody)
spring·http·mvc
VaporGas3 天前
JSP经典设计模式流程分析:JSP+JavaBean设计模式+MVC设计模式
java·设计模式·mvc·jsp·javabean
惜.己3 天前
基于Spring搭建SpringMvc框架
java·开发语言·后端·spring·tomcat·mvc·idea
键盘敲没电6 天前
【iOS】MVC模式
ios·mvc·objective-c·xcode
安和昂6 天前
【iOS】MVC入门
ios·mvc
Faith-J7 天前
在 Spring MVC 中部署路由为history模式的vue项目
vue.js·spring·mvc
码里法8 天前
springmvc用配置类替换xml配置
java·spring·mvc
@@@wang9 天前
Spring MVC
java·spring·mvc