当前位置:   article > 正文

MVC之 IHttpModule管道模型

MVC之 IHttpModule管道模型

在这里插入图片描述

system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules>
      <add name="CustomHttpModule" type="WebApplication6.Utility.CustomHttpModule,WebApplication6"/>
    </modules>
  </system.webServer>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
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        "));
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
注册HttpModule

在注册我们自己编写的 Http Module 之前,先来看看Asp.Net中已经有的HttpModule。与 Http Handler类似,我们需要打开机器上
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config
在这里插入图片描述
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/黑客灵魂/article/detail/820944
推荐阅读
相关标签
  

闽ICP备14008679号