473,320 Members | 1,978 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,320 software developers and data experts.

Catch the close of the application to save info

Hi,

I have an application that needs to save some info in the database when the
user closes the application by clicking the x box in the right top corner of
the window.

I tried the session_end event in the global module but it only fires with
the timeout, not when the app is closed.
Application_end doesn't work either.

I use InProc in web.config.

Thanks
Jan 13 '07 #1
4 1175
"Dan Aldean" <do*******@rogers.comwrote in message
news:eJ**************@TK2MSFTNGP04.phx.gbl...
I have an application that needs to save some info in the database when
the user closes the application by clicking the x box in the right top
corner of the window.
Ah yes - this one comes up fairly regularly...
I tried the session_end event in the global module but it only fires with
the timeout, not when the app is closed.
That's right - the server has no knowledge whatever of what is happening in
the browser until / unless the browser sends it another HttpRequest, due to
the disconnected architecture of the web. This is a common misconception...
Application_end doesn't work either.
Indeed not - Application_End fires when the final live session is torn down,
either through code or through automatic timeout.
I use InProc in web.config.
Irrelevant...

Your only option is to try to use the client-side window.onunload event:
http://www.google.co.uk/search?sourc...ow%2eunload%22

However, be aware that this is not guaranteed to work the same way for all
browsers across all platforms, and will almost certainly also fire if the
user refreshes the page...
Jan 13 '07 #2
Hi,

Dan Aldean wrote:
Hi,

I have an application that needs to save some info in the database when the
user closes the application by clicking the x box in the right top corner of
the window.

I tried the session_end event in the global module but it only fires with
the timeout, not when the app is closed.
Application_end doesn't work either.

I use InProc in web.config.

Thanks
There is no way to detect with certainty when the browser window is closed.

If it's really vital for you to save the information in the DB as soon
as possible, the only way I can think of is having a web service
periodically "ping" the server. When the "ping" stops, it means that the
user closed the window, or that he navigated to another page.

However, the normal way to do things is to use Session_End. Why can't
you wait until Session_End?

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Jan 13 '07 #3
Session timeout is the correct place to do this, so work your strategy
around that and ignore whats happening at the client. Your server code
knows nothing about the browser being closed, or even if it has a window at
all and isn't a simple tcp socket call over http from a webservice.

--
Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
http://www.johntimney.com/blog
"Dan Aldean" <do*******@rogers.comwrote in message
news:eJ**************@TK2MSFTNGP04.phx.gbl...
Hi,

I have an application that needs to save some info in the database when
the user closes the application by clicking the x box in the right top
corner of the window.

I tried the session_end event in the global module but it only fires with
the timeout, not when the app is closed.
Application_end doesn't work either.

I use InProc in web.config.

Thanks

Jan 13 '07 #4
Thank you all for the answers.
Jan 13 '07 #5

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

Similar topics

6
by: DraguVaso | last post by:
Hi, In my application, on some given actions while debugging in Visual Studio, I suddenly get a "System.ComponentModel.Win32Exception was unhandled" Message="Error creating window handle."...
1
by: smitty mittlebaum | last post by:
I have a strange problem that has reared its ugly head in the last few weeks. I have the option "Compact on Close" (Tools, Options, General tab) enabled on my development machine. I did this...
7
by: Dan Bass | last post by:
In a somewhat complex application, I've developed plug-in architecture and am having a problem as to when to catch general exceptions for logging purposes. In each plug-in class library, for...
23
by: VB Programmer | last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally. Example: In order to close/dispose a db connection you have to dim the connection outside of the Try Catch Finally...
4
by: tshad | last post by:
Normally, I surround my Dataset/fill or DBreader execut with a try/Catch. Something like: ****************************************************** Dim dbReader As SqlDataReader Dim...
32
by: cj | last post by:
Another wish of mine. I wish there was a way in the Try Catch structure to say if there wasn't an error to do something. Like an else statement. Try Catch Else Finally. Also because I...
0
by: Jared | last post by:
Hi I am developing an intranet based ASP.NET application. Due to high security on site the application needs to run accross two separate domains (only http and https ports are open). The...
12
by: David Lozzi | last post by:
Howdy, I ran into a very interesting issue and I'm curios as to how this is suppose to work. I am using Try...Catch...Finally statements for all database connectivity in my ASP.NET 2.0 web...
4
by: andyehi | last post by:
Dear All, I am new to C# and I am developing an application which will 24hours run on the remote PC..To transfer records from mysql to access db.I have succesfully created the application and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.