Code
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using studentsArchives;
using HnClassDB;
/**//// <summary>
/// PageBase 页面基类
/// 目标
/// 1.定义系统皮肤
/// 2.定义常用的对象
/// 3.覆写页面预处理事件
/// </summary>
public class PageBase : System.Web.UI.Page
{
public PageBase()//构造函数
{
user = new userClass();
}
//私有变量#region//私有变量
private userClass user;//声明用户
#endregion
//公有属性#region//公有属性
/**//// <summary>
/// 返回当前用户的实例
/// </summary>
protected userClass User
{
get
{
try
{
return user;
}
catch
{
return null;
}
}
}
/**//// <summary>
/// 应用程序路径 如:/DgShool
/// </summary>
protected string ApplicationPath
{
get
{
return Request.ApplicationPath.ToString();
}
}
/**//// <summary>
/// 获得远程客户端的IP地址
/// </summary>
protected string UserHostIP
{
get
{
return HttpContext.Current.Request.UserHostAddress;
}
}
#endregion
//覆写页面事件#region//覆写页面事件
/**//// <summary>
/// 覆写页面预处理事件(OnPreInit)
/// </summary>
/// <param name="e"></param>
protected override void OnPreInit(EventArgs e)
{
//从全局变量Session中获得用户信息
if (HttpContext.Current.Session["userAll"] != null)
{
string[] userAll = HttpContext.Current.Session["userAll"].ToString().Split(',');
user.RealName = userAll[5];//真实姓名
user.EmployeeNo = userAll[6];//工号
user.Duty = userAll[7];//职位
user.RoleNo = Convert.ToInt32(userAll[8]);//角色
user.RoleName = userAll[9];//角色名称
//应用主题皮肤
Page.Theme = Session["skinStyle"].ToString();
}
else
{
OnError(e);
}
base.OnPreInit(e);
}
/**//// <summary>
/// 覆写错误处理事件(OnError)
/// </summary>
/// <param name="e"></param>
protected override void OnError(EventArgs e)
{
Server.Transfer(ApplicationPath + "/sysError.aspx", false);
base.OnError(e);
}
/**//// <summary>
/// 覆写OnLoad事件
/// </summary>
/// <param name="e"></param>
protected override void OnLoad(EventArgs e)
{
//清除缓存
Response.Cache.SetNoStore();
base.OnLoad(e);
}
#endregion
}