我用的是mvc的
1、在model写个类VerificationModule.cs (名字随便啊)
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using System.Data;using System.Collections;using RHRSP.Web.Models;using System.Xml;using RHRSP.Web.Controllers.Common;using System.IO;using System.Reflection;using System.Text.RegularExpressions;public class VerificationModule : IHttpModule{ public static int b = 0; public VerificationModule() { } public String ModuleName { get { return "VerificationModule"; } } // In the Init function, register for HttpApplication // events by adding your handlers. public void Init(HttpApplication application) { string s= Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase); application.BeginRequest += (new EventHandler(this.Application_BeginRequest)); application.EndRequest += (new EventHandler(this.Application_EndRequest)); } private void Application_BeginRequest(Object source, EventArgs e) { // Create HttpApplication and HttpContext objects to access // request and response properties. HttpApplication application = (HttpApplication)source; HttpContext context = application.Context; // string s = context.Request.Url.ToString(); string filePath = context.Request.FilePath; string fileExtension = VirtualPathUtility.GetExtension(filePath); if (fileExtension.Equals("/Index/Index")) { context.Response.Write("" + "VerificationModule: Beginning of Request" + "
"); } } private void Application_EndRequest(Object source, EventArgs e) { HttpApplication application = (HttpApplication)source; HttpContext context = application.Context; string filePath = context.Request.FilePath; string fileExtension = VirtualPathUtility.GetExtension(filePath); if (fileExtension.Equals(".aspx")) { context.Response.Write("" + "VerificationModule: End of Request
"); } } public void Dispose() { }}
2、然后在web.config 添加下面这个
<system.web>
<httpModules> <add name="VerificationModule" type="VerificationModule" /> </httpModules></system.web>