Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Session_End in Global.asax

Status
Not open for further replies.

evaleah

Programmer
Mar 18, 2003
252
US
I want to be able to record when a user discontinues use of my application by calling a SQL stored proc. I have put the call in Session_End in my Global.asax file and it doesn't seem to ever get called. I tried the same thing in Application_End but I think that is not really the place I want.

I can successfully record when they log on using Application_Start. Is there something I am missing to get the same thing when they leave?

Thanks!!!
 
The session takes a while to time out. The client doesn't keep a line of communication open with your server (it just makes a periodic request), so your server can only assume when a user's session should end (and the server will wait X amount of time before making that assumption).

Try changing the session timeout and see if you get the results you want.
 
evaleah,
Session_End is the right place to put your code but remember that the Session_End event will not be fired until the Session expires. Your web.config file contains an entry that sets the number of minutes of inactivity that must go by beofore a session will expire. The default value is 30 minutes I believe. This means that the code in Session_End won't run until 30 minutes after the user closes its browser.

For testing purposes, set the timeout of your sessionState to 1 minute in your web.config file, as in:
Code:
<sessionState mode="InProc" ... timeout="2"/>
Then, run your application; don't do anything for a minute, and check that the code in Session_End gets executed.

JC

Oh Wow!!! I was unaware of all the smileys available here at tek-tips.
[rockband]
 
Hey BoulderBum, you beat me to it!

JC

Oh Wow!!! I was unaware of all the smileys available here at tek-tips.
[rockband]
 
My timeout is set for 20 minutes in my web.config file. For testing I waited until session timed out. I got the friendly session time out page I had created but the event in my global.asax didn't ever fire. Any explanation for why that would be?

I have only tried this in my test environment. Does that make a difference?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top