473,386 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to end a session when the user closes the browser?

Hi everyone,

I need some help (may be in the form of some sample code) for the subject
question.

I have an ASP.NET/C# application. I need to do quite a few tasks when the
session ends. I don't want to depend on the session timeout factor since it
may end too soon or it may hang around too long. I can't find any event
that fires when the browser closes. The Session_End event handler in the
Global.asax does not execute until the timeout value expires. Also, when it
does execute the Session_end, it seems that the session has already ended
and so, I have no access to any of the session variables I was holding onto.

Can anybody tell me the server side sequence of events and their handlers
that get called when the user closes a browser? Does the browser inform the
server that it is closing, so that I can do my cleanup?

Any help is highly appreciated.

Babu.
Nov 19 '05 #1
5 9079

Unfortunatly, nothing happens on the server when the browser is closed.
I'm afraid that you can't close the session without waiting the timeout and
the "Session_End" event.

Lionel.
"news.microsoft.com" <ba************@yahoo.com> a écrit dans le message de
news: uB*************@TK2MSFTNGP15.phx.gbl...
Hi everyone,

I need some help (may be in the form of some sample code) for the subject
question.

I have an ASP.NET/C# application. I need to do quite a few tasks when the
session ends. I don't want to depend on the session timeout factor since
it may end too soon or it may hang around too long. I can't find any
event that fires when the browser closes. The Session_End event handler
in the Global.asax does not execute until the timeout value expires.
Also, when it does execute the Session_end, it seems that the session has
already ended and so, I have no access to any of the session variables I
was holding onto.

Can anybody tell me the server side sequence of events and their handlers
that get called when the user closes a browser? Does the browser inform
the server that it is closing, so that I can do my cleanup?

Any help is highly appreciated.

Babu.

Nov 19 '05 #2
Thanks for the reply, Lionel. That was fast!

OK, then, is there another event that fires before the call to the
Session_End handler in the Global.asax? Because by the time the execution
arrives at this handler, I have no access to any of the Session variables
(It seems that the session has already been removed). If only I could find
an event that fires with the session state intact just before the session
closes.

Babu.

"Lionel LASKE" <ll****@c2s.fr> wrote in message
news:es**************@TK2MSFTNGP14.phx.gbl...

Unfortunatly, nothing happens on the server when the browser is closed.
I'm afraid that you can't close the session without waiting the timeout
and the "Session_End" event.

Lionel.
"news.microsoft.com" <ba************@yahoo.com> a écrit dans le message de
news: uB*************@TK2MSFTNGP15.phx.gbl...
Hi everyone,

I need some help (may be in the form of some sample code) for the subject
question.

I have an ASP.NET/C# application. I need to do quite a few tasks when
the session ends. I don't want to depend on the session timeout factor
since it may end too soon or it may hang around too long. I can't find
any event that fires when the browser closes. The Session_End event
handler in the Global.asax does not execute until the timeout value
expires. Also, when it does execute the Session_end, it seems that the
session has already ended and so, I have no access to any of the session
variables I was holding onto.

Can anybody tell me the server side sequence of events and their handlers
that get called when the user closes a browser? Does the browser inform
the server that it is closing, so that I can do my cleanup?

Any help is highly appreciated.

Babu.


Nov 19 '05 #3
re:
Unfortunatly, nothing happens on the server when the browser is closed.
Right.

re: I'm afraid that you can't close the session without waiting the timeout
and the "Session_End" event.
You can programmatically call Session.abandon
to force the end of a session at any time.

That won't help Babu at all, but ending the session *can* be
done without the need to wait for the timeout or Session_End.

One way to persist session values, so they're restored the next
time the visitor returns, would be to dump the session values into
a cookie named with the SessionID. Each time you add a Session
variable, you add a cookie key with the variable's value.

When the user returns, reading the cookie would enable
you to set the same values to the current session.

Alternately, you could dump the session values into a db table,
using the SessionID as the key. Then, reading a simple cookie
set with a key name = SessionID would allow you to set the
current session values to the previous session values.

Why you'd want to do that beats me, but it's not too hard to do.

Juan T. Llibre
ASP.NET MVP
===========
"Lionel LASKE" <ll****@c2s.fr> wrote in message
news:es**************@TK2MSFTNGP14.phx.gbl...
Unfortunatly, nothing happens on the server when the browser is closed.
I'm afraid that you can't close the session without waiting the timeout
and the "Session_End" event.

Lionel.
"news.microsoft.com" <ba************@yahoo.com> a écrit dans le message de
news: uB*************@TK2MSFTNGP15.phx.gbl...
Hi everyone,

I need some help (may be in the form of some sample code) for the subject
question.

I have an ASP.NET/C# application. I need to do quite a few tasks when
the session ends. I don't want to depend on the session timeout factor
since it may end too soon or it may hang around too long. I can't find
any event that fires when the browser closes. The Session_End event
handler in the Global.asax does not execute until the timeout value
expires. Also, when it does execute the Session_end, it seems that the
session has already ended and so, I have no access to any of the session
variables I was holding onto.

Can anybody tell me the server side sequence of events and their handlers
that get called when the user closes a browser? Does the browser inform
the server that it is closing, so that I can do my cleanup?

Any help is highly appreciated.

Babu.


Nov 19 '05 #4
Babu,

You do have some limited possibilities. You can use
Response.IsClientConnected. Google for it to find out how it can help.

Eliyahu

"news.microsoft.com" <ba************@yahoo.com> wrote in message
news:uB*************@TK2MSFTNGP15.phx.gbl...
Hi everyone,

I need some help (may be in the form of some sample code) for the subject
question.

I have an ASP.NET/C# application. I need to do quite a few tasks when the
session ends. I don't want to depend on the session timeout factor since it may end too soon or it may hang around too long. I can't find any event
that fires when the browser closes. The Session_End event handler in the
Global.asax does not execute until the timeout value expires. Also, when it does execute the Session_end, it seems that the session has already ended
and so, I have no access to any of the session variables I was holding onto.
Can anybody tell me the server side sequence of events and their handlers
that get called when the user closes a browser? Does the browser inform the server that it is closing, so that I can do my cleanup?

Any help is highly appreciated.

Babu.

Nov 19 '05 #5

write session.RemoveAll()in the following code
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application ends
Session.RemoveAll()
End Sub

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Rafael Chemtob | last post by:
Hi, I'm using session cookies on my web app and it looks like the session is not being killed when the user closes the browser. We use a Global.asa file on our app. Do we have to explicitly...
1
by: LordHog | last post by:
Hello all, I am a small application that I am developing which will use a few threads. When the user closes the form the threads will remain present until I close them. The Main Form...
2
by: Robert V. Hanson | last post by:
If you have per user information that you want to store in session and the setting in web.config is set to cookieless=false so you are intending on using cookies, the user's browser is set to not...
1
by: feng | last post by:
Hi, When user closes a browser window by clicking on the "X" button, I want the server to be noticed (either through postback or calling other ASP pages, etc.) and perform some task...
4
by: Keith-Earl | last post by:
I thought for sure Session End would fire when the user closes his browser, but no luck. The only way I can get the event to fire is to run a Session.Abandon, but is that really practicle? When a...
3
by: Charlie | last post by:
Hi: I would like to clear session when user closes browser window by clicking the "x" in upper right hand corner. Since this is a client side event, how do I run server code (Session.Abandon())...
4
by: =?Utf-8?B?RGVhbiBHYXJyZXR0?= | last post by:
I'm writing a .NET 2.0 app that needs to manage user sessions. We're using SQL Server 2005 tables to hold sessions status fields in a table. The problem is how to handle the situation where a user...
3
by: spoonybard | last post by:
Hi Everyone, I have a .Net 2.0 C# web application that has important information stored in Sessions that needs to be deleted when the user closes the browser. I know of three ways a user can close...
2
by: gsherp | last post by:
How does one execute code when the user closes the browers window by clicking on the top right corner . I need to log out user and do a database write when the user closes the brower. I do these to...
2
by: chazzy69 | last post by:
Basically i was wondering how to open a popup window, when the user closes either a website i.e. leaving the website; or closes the entire browser. Thanks for any help
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.