pipeline httpmodule
using System;
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Web; namespace pipeline.App_Start { /// <summary> ///对Httpapplication 中的一系列事件进行注册,叫做Ihttpmodule ,这样就可以管道中进行的一系列事件, 大概有19个事件 /// httpmodule作用: 日志、性能监控、权限、缓存、页面加东西、请求过滤、 /// </summary> public class CustomHttpModule : IHttpModule { public void Init(HttpApplication context) { // 注册beginRequest context.BeginRequest += (s, e) => { Debug.WriteLine("BeginRequest"); }; context.AcquireRequestState += (s, e) => { Debug.WriteLine("AcquireRequestState"); }; context.Error += (s, e) => { Debug.WriteLine("Error"); }; context.Disposed += (s, e) => { Debug.WriteLine("Disposed"); }; context.PostResolveRequestCache += (s, e) => { Debug.WriteLine("PostResolveRequestCache 缓存"); }; context.PostReleaseRequestState += (s, e) => { Debug.WriteLine("PostReleaseRequestState"); }; context.PostResolveRequestCache += (s, e) => { // System.Web.Routing.UrlRoutingModule MVC 其实就是一个扩展 Debug.WriteLine("PostReleaseRequestState"); // MVC 就是 httpmodule扩展,通过URLroutemodule }; context.PreRequestHandlerExecute += (s, e) => { Debug.WriteLine("PreRequestHandlerExecute"); }; context.MapRequestHandler += (s, e) => { Debug.WriteLine("MapRequestHandler"); }; context.PostAuthorizeRequest += (s, e) => { Debug.WriteLine("PostAuthorizeRequest"); }; context.EndRequest += (s, e) => { Debug.WriteLine("EndRequest"); }; } public void Dispose() { throw new NotImplementedException(); } } }
<system.webServer> <validation validateIntegratedModeConfiguration="false" /> <modules> <!--集成模式下httpmodule的配置--> <add name="CustomHttpModule" type="pipeline.App_Start.CustomHttpModule"/> <!--不用的事件可以移除,提高性能,如下--> <remove name="FormsAuthoriztion"/> </modules> </system.webServer>