views:

303

answers:

3

Hi,

During Session Start, one has access to the Request object. How about Session End, does it still have access to the Request object ? For example I want to count how many browsers are currently connected to my application.

Edit 1 : If Session End doesn't have access to Request Object, what info does it have access to ? Session ID, etc ?

Edit 2 : If Session End cannot be used to track disconnections, how does one track disconnections in ASP.Net ?

Thanks

+1  A: 

No, the Request object is not available in Session End.

Note too that Session End only fires when you call Session.Abandon() from code, not when a Session expires due to natural timeout or what-have-you. Consequently, it is not a reliable method to use for tracking disconnections.

Rex M
Hi Rex, thanks for your reply, how does one track the currently connected browser sessions in my application (eg Firefox 5 sessions, IE 10 sessions, etc).
Michael Ellick Ang
From the MSDN docs "The Session_OnEnd subroutine is run when the Abandon method has been called or when the session has expired." http://msdn.microsoft.com/en-us/library/ms178583(VS.80).aspx
Greg B
@GregB it does say that, but the first time I tried to figure out why Session_End wasn't working the way I expected, I left a debugger attached to the process with a breakpoint on my Session_End event and it was never hit, unless I explicitly called Session.Abandon()
Rex M
A: 

from the documentation

The Session_OnEnd event occurs when a session is abandoned or times out. Of the Server built-in objects, only the Application Object, Server Object, and Session Object objects are available.

Remarks

You cannot call the Server.MapPath method in the Session_OnEnd script. By default, Session_OnEnd runs as the Anonymous User, as defined for the application. In the event that there isn't an Anonymous user, or the Logon for the Anonymous user fails, the OnEnd function will not be called, and an event will be logged.

Christian Hagelid
I've never seen Session End fired when a session times out. Have you?
Rex M
@Rex M: Session End only fires if you use in-process sessions, not if you use the state server or SQL Server as a session store.
Rytmis
+1  A: 

Session_End will be fired if one is using InProc.

Session_End will be fired 1) after n minutes of inactivity (n = timeout value), or 2) if someone calls Session.Abandon()

Session_End doesn't get fired if one closes the browser.

Session_End requires session state to be set.

If one needs the original Request.Browser data, one should save it in Session State.

During Session_End, it has access to the Session State.

Michael Ellick Ang
Can you provide an example of how to access the session in Session_End. I can't get to it...
Greg B
void Session_End(object sender, EventArgs e) { string str = Session[browser]; }
Michael Ellick Ang