我如何可以访问会话在preINIT功能asp.net? [英] how can I access Session in preinit function in asp.net?

查看:141
本文介绍了我如何可以访问会话在preINIT功能asp.net?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 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";
    }
}

我要检查我的会话值,然后根据它,我使用同一个主网页上加载不同的页面的母版页。

I want to check my session value and then load the master page according to it, I am using same master page on the different pages.

推荐答案

让你的类实现<一个href=\"https://msdn.microsoft.com/en-us/library/system.web.sessionstate.irequiressessionstate(v=vs.110).aspx\"相对=nofollow> IRequiresSessionState
如:

Allow your class to implement IRequiresSessionState such as:

public partial class YOUR_ASPX: System.Web.UI.Page , IRequiresSessionState
{
 // your preinit code

}

这是这意味着不需要实现什么,但可以访问会话标志接口。

this is a flag interface which means not need to implement anything but allows you to access Session.

这篇关于我如何可以访问会话在preINIT功能asp.net?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆