March 9, 2021
Hot Topics:

ASP.NET Secrets, Part 5

  • By Karl Moore
  • Send Email »
  • More Articles »

What to Do When Session_End Doesn't Work

It's one of the most common complaints on the newsgroups: "Hey! My Session End event doesn't fire. The code I want to run when the Session finishes just never runs." And then you get the whiz kid that replies with: "It's a bug. You can't rely on it on that End event. Use another method."

Important note: the whiz kid is wrong.

If the code you've entered in your Global.asax file to run when the Session End event fires doesn't appear to be kicking in, there are just three things that could be at fault:

  1. You're not using InProc—The mode attribute of the <sessionState> element in your application Web.config file must be set to "InProc". If it isn't, the End event simply cannot fire.
  2. You're not using the Session—The Session End event can't fire if there's no Session to End. Are you sure your application is storing information through the Session object?
  3. Your code is flawed—There's an error somewhere in the code that responds to the End event. Try running your application in debug mode, with a short <sessionState> timeout attribute. Visit the page and then wait. Does the End event kick in? Does an error occur in your code?

There is quite seriously no other excuse for your code not running. There's no mysterious bug. There are no weird setup issues or reasons for not trusting the Session End event. It works, no excuses.

Page 2 of 4

This article was originally published on April 21, 2003

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date