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

相关推荐
醇氧3 天前
MVC、MVP、MVVM 架构详解、分析与对比
架构·mvc
IKUN家族3 天前
Spring MVC(五)
java·spring·mvc
风起洛阳@不良使4 天前
Spring MVC的前端控制器配置(servlet+DispatcherServlet)
前端·spring·mvc
萧瑟余晖4 天前
Java深入解析篇十六之Spring MVC与WebFlux
java·spring·mvc
IKUN家族6 天前
Spring MVC(四)
java·spring·mvc
额恩6612 天前
神经网络入门:从基础到CNN全解析
mvc
周倦岚12 天前
ArkTS中的MVC、MVP、MVVM
华为·mvc·harmonyos
IKUN家族13 天前
Spring MVC(一)
java·spring·mvc
米码收割机14 天前
【SSM】Spring MVC_MyBatis SSM商城系统(源码+论文)【独一无二】
spring·mvc·mybatis
中微极客17 天前
神经形态计算:从忆阻器到SNN训练工程实践
人工智能·mvc