473,662 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Detecting browser close (X) event in ASP.NET

Hello,

I'm writing trace log of various actions happening in my ASP.NET web
application by opening a text file when the user logs in to the system and
closing the file while the user logs out. This is especially to nail a
hangout issue.

The problem I'm facing is, when the application hangs and the user closes
the browser using close(X) button I'm not able to close the text
file(handle). This keeps the file handle open and the contents of the file
will be blank if viewed from Windows explorer.

Is there any way to resolve this by executing the statements to close the
file even if the user exits the application by closing the browser and not by
normal logout.

Your valuable ideas/solutions are welcome!

Thanks,
Mammen
Apr 20 '06 #1
4 6954
Hi,

You could possibly catch IE's document.onbefo reunload event in
javascript causing a postback before termination. (this would probably
only work in newer ie browsers).

HTH

Apr 20 '06 #2
Hello,

There is no special ASP.NET event for that.

You can do the following:

1.) I think there is a javascript/jscript event fired in body called
"onclose" (please have a look at the web).

2.) Close your file when the session times out -> ASP.NET Event
"Session_On End" (e.g. in VB.NET)

3.) Use the powerful ASP.NET built-in trace functionality instead of
writing your own. There is also a tool called log4net available for
tracing/logging string to files/databases and so on.
Please also look at the web for this.

Bet regards
Sven

Apr 20 '06 #3
mammen wrote:
I'm writing trace log of various actions happening in my ASP.NET web
application by opening a text file when the user logs in to the
system and closing the file while the user logs out. This is
especially to nail a hangout issue.
How about only opening the file when you need to write to it and closing it
immediately? Maybe it's that file being open that's causing the hang.
It's as simple as

Dim fsw As New FileStream(curr entLog, FileMode.OpenOr Create,
FileAccess.Writ e, FileShare.Read)
fsw.Position = fsw.Length
Dim w As StreamWriter = New StreamWriter(fs w)
w.WriteLine(Dat eTime.Now.ToLon gTimeString() & vbTab & logData)
w.Close()
The problem I'm facing is, when the application hangs and the user
closes the browser using close(X) button I'm not able to close the
text file(handle). This keeps the file handle open and the contents
of the file will be blank if viewed from Windows explorer.
Where is the hang happening? Is there some client-side JS going wrong, or is
it on the server?

If the client has hung, it cannot tell the server.
If the server has hung, it cannot close the file.
Is there any way to resolve this by executing the statements to close
the file even if the user exits the application by closing the
browser and not by normal logout.


Anyway, the network connection could be dropped with no action from the
server or user.

If you look in microsoft.publi c.inetserver.ii s for some really big posts,
you'll find what debugging tool they're using to generate the log and see
that there are helpful people there who will analyze the log to see what
exactly caused the hang.

HTH

Andrew
Apr 20 '06 #4
Hi Andrew/Sven,

Thanks for your quick and detailed response.

I have decided to include more information in the application trace I'm
generating and analyse it using the trace utility "trace.axd" available with
..NET.

Thanks,
Mammen

"Andrew Morton" wrote:
mammen wrote:
I'm writing trace log of various actions happening in my ASP.NET web
application by opening a text file when the user logs in to the
system and closing the file while the user logs out. This is
especially to nail a hangout issue.


How about only opening the file when you need to write to it and closing it
immediately? Maybe it's that file being open that's causing the hang.
It's as simple as

Dim fsw As New FileStream(curr entLog, FileMode.OpenOr Create,
FileAccess.Writ e, FileShare.Read)
fsw.Position = fsw.Length
Dim w As StreamWriter = New StreamWriter(fs w)
w.WriteLine(Dat eTime.Now.ToLon gTimeString() & vbTab & logData)
w.Close()
The problem I'm facing is, when the application hangs and the user
closes the browser using close(X) button I'm not able to close the
text file(handle). This keeps the file handle open and the contents
of the file will be blank if viewed from Windows explorer.


Where is the hang happening? Is there some client-side JS going wrong, or is
it on the server?

If the client has hung, it cannot tell the server.
If the server has hung, it cannot close the file.
Is there any way to resolve this by executing the statements to close
the file even if the user exits the application by closing the
browser and not by normal logout.


Anyway, the network connection could be dropped with no action from the
server or user.

If you look in microsoft.publi c.inetserver.ii s for some really big posts,
you'll find what debugging tool they're using to generate the log and see
that there are helpful people there who will analyze the log to see what
exactly caused the hang.

HTH

Andrew

Apr 21 '06 #5

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

Similar topics

2
2318
by: Paul Steele | last post by:
Some time ago I tracked down the code for detecting the shutdown event within a C# program. I tested it, it worked, and I moved on. However, I just discovered that the code is no longer working, and I'm baffled. I've done some more Google searches and have come up with the same thing. A portion of the code is below. I call the HookSessionEnding routine in the Load event of the main form, but the shutdown event code never fires. I'm baffled....
3
5870
by: =B= | last post by:
Hi all, I was wondering if anyone has had any luck with trapping the <BODY> onUnload() event in ASP.NET? The thing is, I'm writing code for an Intranet site. The code makes a call to a third-party component (think of it as a lock) when the page loads. Now the OK and Cancel server buttons I can handle and use to release the lock as required. But previously in classic ASP I had been trapping the user hitting the close 'x' button by...
2
3031
by: Sam-Kiwi | last post by:
I've spent the last 6 months developing a pay-per-download website using ASP.NET Users purchase documents and then download them. The intention is that users are only charged for documents they successfuly download. My problem revolves around detecting a successful download, the steps I take to handle the download are as follows:
5
1441
by: Russell | last post by:
Hi all, I have a web page(a) that has a link to another web page(b). Now, on the page load event of web page(b), I am doing the following: Response.redirect("./test.pdf") This pdf, if the user copies the url, can go back to it after they have logged out of my web site. I need to delete this file. I need to find a way to detect the web page is closing so I can delete the pdf file.
1
5569
by: Tuong | last post by:
I have a situation where i have a form that contains a webbrowser control. With this I was able to implement an application that can browse websites. One particular website i visited opens up another web page in a new window and then closes it. I was able to control this action by detecting the 'NewWindow' event and opening the webpage in my own application. Now the problem i have come across is that when the webpage that was opened in...
79
3753
by: VK | last post by:
I wandering about the common proctice of some UA's producers to spoof the UA string to pretend to be another browser (most often IE). Shouldn't it be considered as a trademark violation of the relevant name owner? If I make a whisky and call it "Jack Daniels", I most probably will have some serious legal problems. "Mozilla" partially appeared because NCSA stopped them from using "Mosaic" in the UA string. Is it some different...
3
7240
by: somaskarthic | last post by:
Hi I am trying to use Javascript in order to detect when a user presses the little 'X' at the top right hand corner of the window or uses File..Close, in order to process some code before hand. If unload event is used in body tag , then each and every time whenever the form unloads the javascript function would fire. But i want to fire that function only when the close button ( X ) in the top right corner is pressed. Can anyone help me...
6
3934
by: hemant.singh | last post by:
Hi all, I am trying to get a way by which I'll know exactly when user goes out of my site by clicking on close button in browser, So that w/e user click close button in browser, I can send a signal to server. This seems to be achievable with body unload events, but it is little too much, as even if user navigate within my site, this event will be generated, this can be avoided by handling onclick of each link, so that I'll know exactly...
15
4218
by: RobG | last post by:
When using createEvent, an eventType parameter must be provided as an argument. This can be one of those specified in DOM 2 or 3 Events, or it might be a proprietary eventType. My problem is testing for support of particular eventTypes - the DOM 2 Events Interface DocumentEvent says that if the eventType is not supported, it throws a DOM exception. This makes testing rather tough - if you try something like: if (document &&...
0
8432
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
8857
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...
0
8764
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8633
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...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5654
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
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.