如何在Global.asax中获取会话

时间:2013-11-28 07:35:09

标签: asp.net

我在Session UserID 中有价值,我想在global.asax中的函数中访问此id 如果会话过期我可以在 void Session_End(对象发送者,EventArgs e)中得到它。否则它显示错误会话状态在此上下文中不可用

怎么办?

2 个答案:

答案 0 :(得分:1)

尝试使用HttpApplication.AcquireRequestState

访问HttpContext.Current.Session事件中的会话值
protected void Application_AcquireRequestState(object sender, EventArgs e)
{
  //Some code here
  string strYourKey = HttpContext.Current.Session["YourKey"].ToString();
}

答案 1 :(得分:0)

试试这个

if (HttpContext.Current != null &&
    HttpContext.Current.Session != null) {
  var data= HttpContext.Current.Session["sessionvariablename"];
}

链接

http://forums.asp.net/t/1661936.aspx

相关问题