博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OnPreInit,OnInit ,OnInitComplete ,OnPreLoad ,Page_Load等执行顺序
阅读量:5058 次
发布时间:2019-06-12

本文共 2942 字,大约阅读时间需要 9 分钟。

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class Default5 : System.Web.UI.Page{    static int count = 0;    protected void Page_Load(object sender, EventArgs e)    {        Response.Write(count + "Page_Load 
"); count++; } protected override void OnPreInit(EventArgs e) { base.OnPreInit(e); Response.Write(count + "OnPreInit
"); count++; } protected override void OnInit(EventArgs e) { base.OnInit(e); Response.Write(count + "OnInit
"); count++; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); Response.Write(count + "OnLoad
"); count++; } protected override void OnPreLoad(EventArgs e) { base.OnPreLoad(e); Response.Write(count + "OnPreLoad
"); count++; } protected override void OnLoadComplete(EventArgs e) { base.OnLoadComplete(e); Response.Write(count + "OnLoadComplete
"); count++; } protected override void OnInitComplete(EventArgs e) { base.OnInitComplete(e); Response.Write(count + "OnInitComplete
"); count++; } protected override void OnUnload(EventArgs e) { base.OnUnload(e); } protected override void OnDataBinding(EventArgs e) { base.OnDataBinding(e); Response.Write(count + "OnDataBinding
"); count++; } protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); Response.Write(count + "OnPreRender
"); 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
"); count++; }}

 

结果为:

0OnPreInit 

1OnInit 
2OnInitComplete 
3OnPreLoad 
4Page_Load 
5OnLoad 
6OnLoadComplete 
7OnPreRender

 

*session失效或者超时的跳转(站长后台)

判断页面(每个页面调用)

protected override void OnPreInit(EventArgs e){        new Users().GetUserInfoCookie(out _mywebhostid, out _myuserid);        if (_myuserid == string.Empty || _mywebhostid == 0)        {            Response.Redirect("~/login.aspx?reurl=" + HttpUtility.UrlEncode(Request.Url.AbsoluteUri));        }        else        {            new Users().GetUserInfoCookie(out _mywebhostid, out _myuserid);        }        base.OnPreInit(e);}

 

登录页面

string strIp = Request.UserHostAddress; string strSuccessUrl = Request.QueryString["reurl"] == null ? "~/index.aspx" : HttpUtility.UrlDecode(Request.QueryString["reurl"].ToString()); Users u = new Users(); string loginMsg = u.LoginMsg(strUserId, strPassword, Request.UserHostAddress); u.LoginMsg2(strUserId, Request.UserHostAddress, Request.UserAgent, 1); // 登录跳转到成功页面 if (loginMsg == string.Empty) {     LoginLog();     Response.Redirect(strSuccessUrl); }

 

转载于:https://www.cnblogs.com/wolfocme110/p/4173182.html

你可能感兴趣的文章
关于js sort排序方法
查看>>
JAVA面试常见问题之Redis篇
查看>>
javascript:二叉搜索树 实现
查看>>
网络爬虫Heritrix源码分析(一) 包介绍
查看>>
__int128的实现
查看>>
Problem - 1118B - Codeforces(Tanya and Candies)
查看>>
jdk1.8 api 下载
查看>>
svn 图标不显示
查看>>
getElement的几中属性介绍
查看>>
iOS 使用Quartz 2D画虚线 【转】
查看>>
平面最接近点对
查看>>
HTML列表,表格与媒体元素
查看>>
PHP、Java、Python、C、C++ 这几种编程语言都各有什么特点或优点?
查看>>
感谢青春
查看>>
Jquery Uploadify4.2 falsh 实现上传
查看>>
雨林木风 GHOST_XP SP3 快速装机版YN12.08
查看>>
linux基础-命令
查看>>
java对象的深浅克隆
查看>>
Hadoop流程---从tpch到hive
查看>>
数据结构3——浅谈zkw线段树
查看>>