473,399 Members | 2,278 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,399 software developers and data experts.

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 6931
Hi,

You could possibly catch IE's document.onbeforeunload 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_OnEnd" (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(currentLog, FileMode.OpenOrCreate,
FileAccess.Write, FileShare.Read)
fsw.Position = fsw.Length
Dim w As StreamWriter = New StreamWriter(fsw)
w.WriteLine(DateTime.Now.ToLongTimeString() & 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.public.inetserver.iis 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(currentLog, FileMode.OpenOrCreate,
FileAccess.Write, FileShare.Read)
fsw.Position = fsw.Length
Dim w As StreamWriter = New StreamWriter(fsw)
w.WriteLine(DateTime.Now.ToLongTimeString() & 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.public.inetserver.iis 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
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,...
3
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...
2
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...
5
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...
1
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...
79
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...
3
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....
6
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...
15
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...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
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...
0
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...
0
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...

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.