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 ?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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() ??
Method 2
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)
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0