Session_OnEnd or Session_End events in global.asax won't fire if you store ASP.NET sessions out of proc (in State Server or SQL Server)


This is an overlooked behavior which may break your ASP.NET application if you are using Session_OnEnd or Session_End events in Global.asax. Here is a snippet from related article from MSDN:

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

So, please pay attention to this change if you are planning to move your sessions from InProc to State Server or SQL Server. If you have code in Session_End or Session_OnEnd methods in Global.asax then you may need to find an alternative way to call them as these methods will be ignored after moving sessions to OutProc.

Reference:

SessionStateModule.End Event
http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatemodule.end.aspx

Applies To:

All ASP.NET versions

--
AMB

Comments (4)

  1. shahrooz says:

    What is the alternative way?

  2. @shahrooz - hello, session_onend events are used for cleanup purposes, what kind of cleanup it is needed when you use outProc sessions and what is your implementation in your session_onend functions?

  3. chanti says:

    wanted to redirect to error page (suppose) with mode sql server on session then how can we do that.?

  4. @chanti - hi, could you please elaborate your question a bit? what would you like to achieve and how is that related with the sessions? thanks...

Skip to main content