cannot access Session Variables

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?
 
H

Hans Kesting

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
 
J

Jeff Siver

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,088
Latest member
JeremyMedl

Latest Threads

Top