bageesh
bageesh

Reputation: 83

How to get session in Global.asax

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

Answers (2)

Adil
Adil

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

Monika
Monika

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

Related Questions