views:

166

answers:

3

Hi folks,

i want to check if the Session contains some key/value data, in my global.asax. I'm not sure when the earliest possible time (and method name) is, to check this.

thanks :)

A: 

According to link text, the earliest events in global.asax that you can access session objects is when global.asax fires Session_Start event

Session__Start: Fired when a new user visits the application Web site.
Session__End: Fired when a user's session times out, ends, or they leave the application Web site

Funky81
Those will only fire the first time someone visits a site, not during every request
Slace
+2  A: 

You need to use BeginRequest (http://msdn.microsoft.com/en-us/library/system.web.httpapplication.beginrequest.aspx) as it is the first event fired on the HttpApplication object (which the Global.asax inherits).

You'll see more about the ASP.NET Application Lifecycle here - http://msdn.microsoft.com/en-us/library/ms178473.aspx (this is for IIS 5 & IIS 6).

Slace
It might be the first _event_ fired on the HttpApplication object, but has the session be deserialised, by then?
Pure.Krome
According to the lifecycle the HttpContext has been created, which HttpSessionState is a property of
Slace
apparently this Answer is incorrect according to http://stackoverflow.com/questions/1704940/when-is-the-earliest-i-can-access-session-in-the-asp-net-mvc-page-lifecycle
andy
A: 

I always believed Application_AcquireRequestState was the first event in Global.asax that could access the current session. It's definitely not Application_BeginRequest.

ddc0660