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

相关推荐
Foreer黑爷1 天前
Spring MVC原理与源码:从请求到响应的全流程解析
java·spring·mvc
曹牧2 天前
Spring MVC中使用HttpServletRequest和HttpServletResponse
java·spring·mvc
曹牧2 天前
Spring MVC配置文件
java·spring·mvc
CPUOS20103 天前
嵌入式C语言高级编程之MVC设计模式
c语言·设计模式·mvc
xxjj998a3 天前
【Spring】Spring MVC案例
java·spring·mvc
医疗信息化王工7 天前
基于ASP.NET Core的医院输血审核系统设计与实现
后端·mvc·asp.net core·输血审核
johnrui7 天前
WebFlux 与普通HTTP(Spring MVC)详细对比
spring·http·mvc
MX_93598 天前
Spring MVC全注解开发实现及其原理
java·spring·mvc
凯尔萨厮9 天前
创建SpringWeb项目(Spring3.2+)
spring·mvc
lingggggaaaa10 天前
PHP模型开发篇&MVC层&动态调试未授权&脆弱鉴权&未引用&错误逻辑
开发语言·安全·web安全·网络安全·php·mvc·代码审计