我如何在asp.net的preinit函数中访问会话
本文关键字:函数 preinit 访问 会话 net asp | 更新日期: 2023-09-27 18:04:47
void Page_PreInit(Object sender, EventArgs e)
{
HttpCookie userInfo;
userInfo = Request.Cookies["userInfo"];
Session["EmpID"] = userInfo["EmpID"];
Session["GroupID"] = userInfo["GroupID"];
Session["DeptID"] = userInfo["DeptID"];
Session["SecID"] = userInfo["SecID"];
if (Session["GroupID"] =="1")
{
this.MasterPageFile = "master/hr_dept.Master";
}
else if (Session["GroupID"] == "2")
{
this.MasterPageFile = "master/hr_dept.Master";
}
else if (Session["GroupID"] == "3")
{
this.MasterPageFile = "master/hod_dept.Master";
}
else if (Session["GroupID"] == "4")
{
this.MasterPageFile = "master/default2_dept.Master";
}
else
{
this.MasterPageFile = "master/site.Master";
}
}
我想检查我的会话值,然后根据它加载母版页,我在不同的页面上使用相同的母版页。
允许你的类实现IRequiresSessionState如:
public partial class YOUR_ASPX: System.Web.UI.Page , IRequiresSessionState
{
// your preinit code
}
这是一个标志接口,意味着不需要实现任何东西,但允许您访问会话。