Search code examples
c#asp.netauthenticationsessionmembership

How do you programmatically end a session in asp.net when Session.Abandon() doesn't work?


Session.Abandon() doesn't seem to do anything. You would expect the Session_end event to fire when Session.Abandon() is called.


Solution

  • This is most likely because your SessionMode is not InProc (the only one that can detect when a session ends).

    Quoted from MSDN:

    Session Events

    ASP.NET provides two events that help you manage user sessions. The Session_OnStart event is raised when a new session starts, and the Session_OnEnd event is raised when a session is abandoned or expires. Session events are specified in the Global.asax file for an ASP.NET application.

    The Session_OnEnd event is not supported if the session Mode property is set to a value other than InProc, which is the default mode.