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

How to catach a close event on a website without javascript?

How can i catch a close event on a web page without the use of javascript. I have a site that a users has to log in to and from that I have to keep track of if they are logged in or not. My problem now comes when the user has to be marked as logged out. How can I solve the problem that when the browser closes unexpectedly that it then carries out a method that will mark the user as logged out. The log out methods works when the users logs out and then closes the application.
Nov 17 '08 #1
7 1349
kenobewan
4,871 Expert 4TB
I'd look at the application events in the global.asax file:
Working with the ASP.NET Global.asax file
Nov 17 '08 #2
balabaster
797 Expert 512MB
The application events are only fired when IIS is started/stopped.

As far as I'm aware - please someone yell if I'm mistaken, but so far from everything I've read or been told, the following is true:

Because the client (read: web browser) is completely disconnected from the server, there's no way to detect if the browser is closed without it being told to communicate its action with the server. There are a limited number of methods of doing this: Client script (client side Javascript/VBScript); Java applet; ActiveX control. The simplest is using one of the Javascript methods below:

Javascript Solutions:

1). Send a heartbeat to the server once every xx number of seconds. The server has a timer that counts down to 0. Once the timer reaches 0, the session is dropped and the user once again has to log in. The heartbeat continuously resets the timer to it's starting point so it can never reach 0 so long as the page is open.

2). Set the session timeout sufficiently high that for all intensive purposes it never times out, but when the window is closed a javascript sends a signal to the server to notify it that the page has closed.

ActiveX/Java Applet Solutions:

Embed an active-x or java applet into the web page that does the equivalent of one of the Javascript solutions. My feeling is that the most likely candidate would be option 1.

If no client side scripting or control embedding is possible due to network security restrictions then there is no way to tell the client browser that it must notify the server when its closed or when you navigate away from the site. In which case, you have to rely on the session timeout to kill the session in a sufficiently small enough amount of time that a new session must be started.

Perhaps you could use some trickery to prevent someone from navigating directly to pages within your application by entering the address in the address bar, i.e. some token is passed from page to page. If the token is missing, then the site automatically redirects the user to a starter page where they must log in to obtain this token. Once they have this token, they can only navigate from page to page using links or form buttons - of course, things like postback all require javascript in order to run properly, so if javascript isn't allowed, then a lot of this functionality is rendered useless.

So given that this is the case, you'd have to navigate using buttons, anchor tags wouldn't work as they use GET instead of POST and as such, you couldn't pass a hidden token, which would mean the user could navigate to a page just by pasting the address into the address bar...
Nov 17 '08 #3
Plater
7,872 Expert 4TB
If no client side scripting
If that were really the case, NO ASP.NET page would function.
They all rely on javascript.

And the Application functions fire when the application is started/restarted/stopped/etc (which would include when IIS as a whole is started/stopped/etc). It is possible to stop/start/etc a webapplication on IIS without affecting any of the others.
Nov 17 '08 #4
balabaster
797 Expert 512MB
And the Application functions fire when the application is started/restarted/stopped/etc (which would include when IIS as a whole is started/stopped/etc). It is possible to stop/start/etc a webapplication on IIS without affecting any of the others.
To clarify further the application should be thought of as the application running on the server, not the application running in the web client...(i.e. the pages served to this user within their session).
Nov 17 '08 #5
boyank
5
Here is solution without using JavaScript. It involves more work but it's doable:

1. Create a unique session ID for the user when the user logs in
2. With each session ID also store the login time
3. Set a treshold for inactivity somewhere which indicates after how long the user is considered inactive and/or logged out
4. Run a process on the server to clean up expred sessions that match the login time in #2 + the threshold in #3 where < current time
Nov 18 '08 #6
Plater
7,872 Expert 4TB
Here is solution without using JavaScript. It involves more work but it's doable:

1. Create a unique session ID for the user when the user logs in
2. With each session ID also store the login time
3. Set a treshold for inactivity somewhere which indicates after how long the user is considered inactive and/or logged out
4. Run a process on the server to clean up expred sessions that match the login time in #2 + the threshold in #3 where < current time
All that functionality is already built into the Session object (if you use the default "InProc" setting)
Nov 18 '08 #7
balabaster
797 Expert 512MB
All that functionality is already built into the Session object (if you use the default "InProc" setting)
And in addition to that, all it tells you is the last page load on that session - it doesn't tell you if the window's been closed...
Nov 18 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: John H. | last post by:
Hello I have some trouble in closing a window, Here is the problem: I develop a asp.net website use client side valiation <asp:CustomValidator id="CustomValidator1"...
4
by: ...D. | last post by:
OK. I am halfway decent with HTML. Now I want to try javascript for some things that HTML cannot do. I have looked over a tutorial & all. What I want to do is create a button, that when...
9
by: MacDermott | last post by:
I have an Access MDB which instantiates a class in a custom DLL, manipulates it for a while, then sets it equal nothing. The MDB does other things,too, and generally behaves itself as desired....
4
by: Hitesh | last post by:
Hi, I am opening an Modal dialog box using the window.Showmodaldialogbox(), and in that window i am having an aspx form with say one ASP.NET Button control. i am doing some operation on the...
5
by: lindanr | last post by:
In ASP.NET 2005 I have an onblur="window.close()" javascript event in the <body> tag. When I click on the window's scrollbar, the window closes. The same code works fine in ASP.NET 2003. Any...
3
by: Todd Jaspers | last post by:
Hey guys, I've developed a C# Web Form using Visual Studio 2005. I can't quite figure out how to exit the form though??? On my form, I have a button which says "CLOSE". I'd like for someone to...
5
by: jimmy | last post by:
Hi all, I want to capture the event when the browser's close button is clicked in an html page. I tried using the event.ClientX and event.ClientY property in the body unload event, and this...
6
by: =?Utf-8?B?UGF1bA==?= | last post by:
I am looking for a java script to close a web form that I can attatch to a button click event. I am using vs2005, c#. Thanks -- Paul G Software engineer.
2
by: pankajsingh5k | last post by:
Dear All, Please help me... I had read an article to lazy load a tab in a tabcontainer using an update panel on http://mattberseth.com/blog/2007/07/how_to_lazyload_tabpanels_with.html ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
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
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.