Reputation: 83
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?
Upvotes: 4
Views: 5789
Reputation: 148180
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();
}
Upvotes: 5
Reputation: 2210
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
Upvotes: 0