cannot access Session Variables

  • Thread starter Thread starter Kaya
  • Start date Start date
K

Kaya

in the Global.asax Application_EndRequest prodecure
the application do something and it works normally
but when i try to use session
it gives errors "Object reference not set to an instance of an object." i
cannot access a Session variable...

System.Web.HttpContext.Current.Session["CurrentUserID"] = 5;
a = (int)System.Web.HttpContext.Current.Session["CurrentUserID"];

this code doesnt work at the Application_EndRequest

Does anybody tell me why?
 
Kaya said:
in the Global.asax Application_EndRequest prodecure
the application do something and it works normally
but when i try to use session
it gives errors "Object reference not set to an instance of an object." i
cannot access a Session variable...

System.Web.HttpContext.Current.Session["CurrentUserID"] = 5;
a = (int)System.Web.HttpContext.Current.Session["CurrentUserID"];

this code doesnt work at the Application_EndRequest

Does anybody tell me why?

It probably isn't the Session that is null, but HttpContext.Current.
Apparently there is no HttpContext anymore when the EndRequest fires.

Hans Kesting
 
I do not believe you can as the Session has ended before the Application_End
event fires. The only thing I can think of is to move your code from
Application_End to Session_End.

Jeff

Kaya said:
ok is there any way to access Session variables
at the Application_EndRequest

Kaya said:
in the Global.asax Application_EndRequest prodecure
the application do something and it works normally
but when i try to use session
it gives errors "Object reference not set to an instance of an object." i
cannot access a Session variable...

System.Web.HttpContext.Current.Session["CurrentUserID"] = 5;
a = (int)System.Web.HttpContext.Current.Session["CurrentUserID"];

this code doesnt work at the Application_EndRequest

Does anybody tell me why?
 
Back
Top