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

相关推荐
萧瑟余晖1 天前
Spring MVC文件上传SSE与WebSocket详解
websocket·spring·mvc
乌暮2 天前
# Spring 入门与 Spring MVC 实战指南:从零理解 IoC 到 RESTful 图书管理
java·开发语言·后端·学习·spring·mvc·restful
萧瑟余晖3 天前
Spring MVC拦截器异常处理与跨域详解
java·spring·mvc
弈栈录10 天前
Spring MVC 请求处理流程与核心源码解析
后端·架构·mvc
换元不配限13 天前
Android 架构演进实战:MVC → MVP → MVVM → MVI
android·架构·mvc·mvvm·mvp·mvi
云絮.14 天前
Spring MVC(二)
服务器·spring·mvc
only-lucky14 天前
QML深入学习七(MVC模块)
学习·mvc
1570925113415 天前
Android 架构模式详解:从 MVC、MVP 到 MVVM
android·架构·mvc
曹牧15 天前
Spring MVC:@RequestMapping
java·spring·mvc
wang_shu_mo_ran23 天前
Spring MVC 常用注解和用法(二)——url,cookie,session
java·mvc