代码:
public class HtmlHttpModule : IHttpModule { public void Dispose() { } public void Init(HttpApplication context) { context.BeginRequest += new EventHandler(context_BeginRequest); context.EndRequest += new EventHandler(context_EndRequest); } void context_EndRequest(object sender, EventArgs e) { HttpApplication application = (HttpApplication)sender; HttpContext context = application.Context; string filePath = context.Request.FilePath; string fileExtension = VirtualPathUtility.GetExtension(filePath); if (fileExtension.Equals(".html") || fileExtension.Equals(".htm")) { //判断缓存是否存在,不存在加入缓存,调用生成静态的类和方法 //产品过期,移除静态文件,302重定向 if (System.IO.File.Exists(context.Server.MapPath(filePath))) { context.Response.WriteFile(context.Server.MapPath(filePath)); context.Response.End(); } } } void context_BeginRequest(object sender, EventArgs e) { HttpApplication application = (HttpApplication)sender; HttpContext context = application.Context; string filePath = context.Request.FilePath; string fileExtension = VirtualPathUtility.GetExtension(filePath); if (fileExtension.Equals(".html") || fileExtension.Equals(".htm")) { context.Response.Write("<hr><h1><font color=red>" + "HelloWorldModule: End of Request</font></h1>"); } } }
谢谢!