復制代碼 代碼如下:
protected void Page_Load(object sender, EventArgs e)
{}
復制代碼 代碼如下:
public class BasePage : System.Web.UI.Page
{
//pageunload事件,并不是指瀏覽器關閉,而是指頁面關閉,所以刷新的時候,依然會執行以下事件
protected void Page_Unload(object sender, EventArgs e)
{
}
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
if (!SessionData.IsLogin())
{//這里寫 跳轉到登陸頁面:例如:
Response.Redirect(string.Format("~/ReLogin.aspx?Page={0}", Request.Path));
}}
復制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ExpressPlatform.Common;
namespace ExpressPlatform.Web.AppCode
{
public class SessionKey
{
public const string UserInfo = "user";
}
/// <summary>
/// 所有session中的數據,在該類管理
/// </summary>
public class SessionData
{
/// <summary>
/// 獲取session 中的 用戶信息
/// </summary>
/// <returns></returns>
public static MdlSessionCustomerInfo GetUserInfo()
{
MdlSessionCustomerInfo userInfo = SessionManager<MdlSessionCustomerInfo>.GetSessionObject(SessionKey.UserInfo);
if (userInfo == null)
{
userInfo = new MdlSessionCustomerInfo();
//把內容儲存到應用程序
SessionManager<MdlSessionCustomerInfo>.SetSessionObject(SessionKey.UserInfo, userInfo);
}
return userInfo;
}
/// <summary>
/// 重新設置session 中的用戶信息
/// </summary>
/// <param></param>
public static void SetUserInfo(MdlSessionCustomerInfo userInfo)
{
SessionManager<MdlSessionCustomerInfo>.SetSessionObject(SessionKey.UserInfo, userInfo);
}
/// <summary>
/// 清楚session中用戶信息
/// </summary>
public static void ClearUserInfo()
{
SessionManager<MdlSessionCustomerInfo>.SetSessionObject(SessionKey.UserInfo, null);
}
/// <summary>
/// 是否登入
/// </summary>
/// <returns></returns>
public static bool IsLogin()
{
bool ret = false;
MdlSessionCustomerInfo userInfo = SessionManager<MdlSessionCustomerInfo>.GetSessionObject(SessionKey.UserInfo);
if (userInfo != null)
ret = true;
return ret;
}
}
}
復制代碼 代碼如下:
public class BasePage : System.Web.UI.Page
新聞熱點
疑難解答
圖片精選