Abe Miessler
Abe Miessler

Reputation: 85056

What happens when a session expires?

What does asp.net do in the background when a session expires? Is the session completely disposed of, or do I need to add something like Session.Abandon(); in my Session_End event in Global.asax?

Upvotes: 0

Views: 507

Answers (3)

Alexei Levenkov
Alexei Levenkov

Reputation: 100547

In-memory state - the object is removed from list of sessions and Session_End is called. For SQL session state nothing happens and data will no longer be returned for future requests with the same session ID since it does not match (ID + non-expired) condition.

You don't need to call Session.Abandon() in Session_End because that event called when session is expired (which is exactly what Abandon does).

Notes

  • normal web applications that use out-of-process session state (SQL on state service) will not receive Session_End event because out-ouf-process state does not fire it.
  • if you need to cleanup SQL session state you can run clenaup task that deletes rows for expired sessions.

Upvotes: 3

Antony Francis
Antony Francis

Reputation: 304

Session will get cleared if you were using inproc session provider so you won't need to call Session.Abandon().

Upvotes: 1

Ofer Zelig
Ofer Zelig

Reputation: 17480

The session is completely disposed. You don't need to do anything special. Session_End is an event that allows you to do things upon session disposal.

Session.Abandon() is a command that lets you terminate a session at will.

Note: If you don't put any variable in the Session, then Session_End will not fire.

Upvotes: 1

Related Questions