473,778 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1190
"Dan Aldean" <do*******@roge rs.comwrote in message
news:eJ******** ******@TK2MSFTN GP04.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*******@roge rs.comwrote in message
news:eJ******** ******@TK2MSFTN GP04.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
3253
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." exception. The problem is that this exception isn't raised somewhere in a method, so it just shows up, and it causes the application to shut down. Is there anyway how to catch this kinds of exceptions? Can I put somewhere a
1
2099
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 because every time I worked on my app it just grew and grew. What started out as a 14Meg file kept growing into a monster of over 90 Megs! System info: Windows XP Pro with SP1
7
1798
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 example, I'm assuming it's throw on errors, and that the core then catches them. I've got proxy classes handling some fiddly details of the plug-ins. Should I allow the exception to bubble to the top most point it can in a call stack, then catch...
23
3083
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 block. But, I prefer to dim them "on the fly" only if needed (save as much resources as possible). A little further... I may wish to create a sqlcommand and datareader object ONLY if certain conditions are met. But, if I want to clean these up in the...
4
1918
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 ConnectionString as String =System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_Connection") Dim objConn as New SqlConnection (ConnectionString) Dim CommandText as String = "Select City,StateCode from zipCodes where
32
6128
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 understand Finally runs whether an error was caught or not, I haven't found a use for finally yet.
0
1218
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 application autenticates users via a form and security info is held in a database table. When users are on either domain they have the same windows username, but the application server is only running on one domain.
12
2695
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 application. I'm connecting to IBM's Universe 10.2 using UniObjects.Net. Anyway, if the connection errors, the Finally closes the connection. What I see happening is that the function in the Finally statement either isn't running or doesn't apply what...
4
4528
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 have to handle the ODBC error and standard error.Basically it has to skip the error and move to next record.I really dont know how to use try catch.I am pasting the code here below.Excuse if I am posting new thread for answered question,Thanks in...
0
9628
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10292
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5368
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.