asp.net 运行机制
下面了解认识httpModule
要创建一个httpModule类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// models 的摘要说明
/// </summary>
public class models:IHttpModule
{
public models()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public void Dispose()
{
throw new NotImplementedException();
}
public void Init(HttpApplication context)
{
context.BeginRequest+=context_BeginRequest;
context.EndRequest+=context_EndRequest;
}
private void context_EndRequest(object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication; //全局变量
app.Response.Write("<h1>结束</h1>");
}
private void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication; //全局变量
app.Response.Write("<h1>开始好像没用了</h1>");
}
}
然后再配置web.config配置相关操作
这里有两个参数 ,name 与type (type必须与你上面创建的httpmodule相同)
注意, 需经过多个httpModule