3
votes

I have value in Session UserID, I want to access this id in a function in global.asax if session expires i can get it in void Session_End(object sender, EventArgs e) other wise it showing error Session state is not available in this context

What to do?

2
As value is stored in current session , after ending that session there memory will be destroyed, so you have to save it on somewhere else if you want to access that value even after Session_End Method - Hammad Sajid

2 Answers

4
votes

Try accessing the value of session in HttpApplication.AcquireRequestState event using HttpContext.Current.Session

protected void Application_AcquireRequestState(object sender, EventArgs e)
{
  //Some code here
  string strYourKey = HttpContext.Current.Session["YourKey"].ToString();
}
0
votes

just try this

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

Link

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