views:

585

answers:

2

Hi,

I'm asking this question out of curiosity.

I noticed this in my global.asax

void Session_End(object sender, EventArgs e)
{
    // Code that runs when a session ends. 
    // Note: The Session_End event is raised only when the sessionstate mode
    // is set to InProc in the Web.config file. If session mode is set to StateServer 
    // or SQLServer, the event is not raised.
}

I want to understand why Session_End event is not captured/raised when the session mode is StateServer or SQLServer ?

+2  A: 

because the ASP.NET Session State it's not in memory anymore...

when using a different process to store the Session State, the IIS does not know (because it is not coupled, the session state is not held by the IIS anymore) when the session ends...

this is specially because the timeouts, I never tried, but does that event fires when you programaticaly call Session.Abandon() ??

balexandre
A: 

The Session_End event is only suported by the InProc session manager:

ASP.NET Session-State Events (MSDN)

"The Session_OnEnd event is supported only when the session state Mode property is set to InProc, which is the default. If the session state Mode is StateServer or SQLServer, then the Session_OnEnd event in the Global.asax file is ignored. If the session state Mode is set to Custom, then support for the Session_OnEnd event is determined by the custom session-state store provider."

This article explains how to use an HttpModule to emulate this functionality:

ASP.NET HttpModule for handling session end with StateServer (CodeProject)

Kev