继承IHttpModule

1、新建一个类库,FilterLibrary
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Web; namespace FilterLibrary { public sealed class HttpModule : IHttpModule { public void Dispose() { throw new NotImplementedException(); } public void Init(HttpApplication context) { context.BeginRequest += new EventHandler(context_BeginRequest); } void context_BeginRequest(object sender,EventArgs e) { HttpApplication application = sender as HttpApplication; HttpContext current = HttpContext.Current; HttpRequest request = current.Request; application.Context.Response.Write("第三方过滤器"+request.RawUrl); } } }
2、web.config中注册
<add name="HttpModule" type="FilterLibrary.HttpModule,FilterLibrary"/>
name:类名,type:命名空间名称+类名,逗号分隔,+命名空间名称
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="DotNetCasClient"/>
<add name="DotNetCasClient" type="DotNetCasClient.CasAuthenticationModule,DotNetCasClient"/>
<!--<add name="FirstModule" type="FilterLibrary,FirstModule"/>-->
<add name="HttpModule" type="FilterLibrary.HttpModule,FilterLibrary"/>
</modules>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*"/>
<add name="Access-Control-Allow-Headers" value="Content-Type"/>
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS"/>
</customHeaders>
</httpProtocol>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
<!--<remove name="OPTIONSVerbHandler" />-->
<remove name="TRACEVerbHandler"/>
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
</handlers>
</system.webServer>

浙公网安备 33010602011771号