public partial class TestControls : System.Web.UI.Page
{
static int count = 0;
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(count+ "Page_Load <br />");
count++;
}
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
Response.Write(count + "OnPreInit <br />");
count++;
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Response.Write(count + "OnInit <br />");
count++;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Response.Write(count + "OnLoad <br />");
count++;
}
protected override void OnPreLoad(EventArgs e)
{
base.OnPreLoad(e);
Response.Write(count + "OnPreLoad <br />");
count++;
}
protected override void OnLoadComplete(EventArgs e)
{
base.OnLoadComplete(e);
Response.Write(count + "OnLoadComplete <br />");
count++;
}
protected override void OnInitComplete(EventArgs e)
{
base.OnInitComplete(e);
Response.Write(count + "OnInitComplete <br />");
count++;
}
protected override void OnUnload(EventArgs e)
{
base.OnUnload(e);
}
protected override void OnDataBinding(EventArgs e)
{
base.OnDataBinding(e);
Response.Write(count + "OnDataBinding <br />");
count++;
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
Response.Write(count + "OnPreRender <br />");
count++;
}
protected void btnGraphics_Click(object sender, EventArgs e)
{
//Bitmap bmp = new Bitmap(10, 10);
//Graphics g = Graphics.FromImage(bmp);
Response.Write(count + "btnGraphics_Click <br />");
count++;
}
}
1.熟悉请求管道实现程序运行的全过程:
(1):BeginRequest: 开始处理请求
(2):AuthenticateRequest授权验证请求,获取用户授权信息
(3):PostAuthenticateRequest获取成功
(4): AunthorizeRequest 授权,一般来检查用户是否获得权限
(5):PostAuthorizeRequest:获得授权
(6):ResolveRequestCache:获取页面缓存结果
(7):PostResolveRequestCache 已获取缓存
(8):PostMapRequestHandler 创建页面对象
(9):AcquireRequestState 获取Session-----先判断当前页面对象是否实现了IRequiresSessionState接口,如果实现了,则从浏览器发来的请求报文体中获得SessionID,并到服务器的Session池中获得对应的Session对象,最后赋值给HttpContext的Session属性
(10)PostAcquireRequestState 获得Session
(11)PreRequestHandlerExecute:准备执行页面对象
执行页面对象的ProcessRequest方法
(12)PostRequestHandlerExecute 执行完页面对象了
(13)ReleaseRequestState 释放请求状态
(14)PostReleaseRequestState 已释放请求状态
(15)UpdateRequestCache 更新缓存
(16)PostUpdateRequestCache 已更新缓存
(17)LogRequest 日志记录
(18)PostLogRequest 已完成日志
(19)EndRequest 完成、
复制代码 代码如下:
public class getsession : System.Web.UI.Page, IReadOnlySessionState
{
string ss = "";
public void Init(HttpApplication context)
{
//这里可以根据需求,添加各个请求管道
//获取Session
context.AcquireRequestState += new EventHandler(context_AcquireRequestState);
//获取Url
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_AcquireRequestState(object sender, EventArgs e)
{
if (Session["user"] != null)
{
ss = Session["user"].ToString();
}
}
void context_BeginRequest(object sender, EventArgs e)
{
//获得当前页面请求管道的HttpApplication对象
HttpApplication application = sender as HttpApplication;
HttpContext context = application.Context;//获得上下文对象
string url = context.Request.Url.LocalPath;//获得URL(不包含域名和路径)
}
}
您可能感兴趣的文章: