473,890 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AJAX: Clientcallback End session on browser close

I have seen several articles about this subject but I was wondering with ajax
is this easer. The articles mentioned client callback and the onbeforeunload
event of the browser. Can AJAX be used for this and are there any examples to
review.

Thank you
--
Jerry
Feb 28 '07 #1
4 2745
Hi,

Jerry C wrote:
I have seen several articles about this subject but I was wondering with ajax
is this easer. The articles mentioned client callback and the onbeforeunload
event of the browser. Can AJAX be used for this and are there any examples to
review.

Thank you
The browser events are not reliable (and also not all are cross-browser
compatible). So using a onunload or onbeforeunload to end the session is
not fool proof.

If you want a sure way, you must use a kind of heart beat. Have the web
client call a web method (might be as simple as a ASHX custom handler
call). As long as the heart beats, the session will not end. If the
heart stops beating, then the session will end automatically after the
Session Timeout set in the web.config. If you want the session to end
immediately, then you'll need to implement some more code, for example a
working thread checking periodically which hearts are still beating.
However, if you set a session timeout of 2 minutes, and the heart beats
every 1 minute, then the waiting time is not that big, and you get the
session to end automatically.

HTH
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Feb 28 '07 #2
Laurent,

Thank you for the reply. I would not have thought of the heartbeat solution.

I have found a article about client callbacks
http://msdn2.microsoft.com/en-us/library/aa479042.aspx

This article may help me program it. Examples are a good thing also if you
have them.

I still would like to find some examples of using the onunload events to
communicate to the server to close the session. Learning how to make browser
events trigger server code will help me in other situations.

Thank you
--
Jerry
"Laurent Bugnion [MVP]" wrote:
Hi,

Jerry C wrote:
I have seen several articles about this subject but I was wondering with ajax
is this easer. The articles mentioned client callback and the onbeforeunload
event of the browser. Can AJAX be used for this and are there any examples to
review.

Thank you

The browser events are not reliable (and also not all are cross-browser
compatible). So using a onunload or onbeforeunload to end the session is
not fool proof.

If you want a sure way, you must use a kind of heart beat. Have the web
client call a web method (might be as simple as a ASHX custom handler
call). As long as the heart beats, the session will not end. If the
heart stops beating, then the session will end automatically after the
Session Timeout set in the web.config. If you want the session to end
immediately, then you'll need to implement some more code, for example a
working thread checking periodically which hearts are still beating.
However, if you set a session timeout of 2 minutes, and the heart beats
every 1 minute, then the waiting time is not that big, and you get the
session to end automatically.

HTH
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Feb 28 '07 #3
Hi,

Jerry C wrote:
Laurent,

Thank you for the reply. I would not have thought of the heartbeat solution.

I have found a article about client callbacks
http://msdn2.microsoft.com/en-us/library/aa479042.aspx

This article may help me program it. Examples are a good thing also if you
have them.

I still would like to find some examples of using the onunload events to
communicate to the server to close the session. Learning how to make browser
events trigger server code will help me in other situations.

Thank you
The major issue with onunload is that it should be also fired when the
browser is closed (using Exit, the "X" button, Alt-F4 or any other
method). However, in that case, the JavaScript engine may very well be
shut down before the XmlHttpRequest has a chance to be sent to the server.

Other events (onload, onresize...) are more reliable. However, having a
safe server-side application is always a good idea, because JavaScript
may be disabled... ;-)

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Feb 28 '07 #4
Laurent

Thank you for the reply. The heartbeat solution seems to be the best one for
my application since it is a inside company application and users will leave
the browser open and attend meetings and go to lunch and expect their session
to be active when they return.

I also would like to mention that the URL I left in my last post is old
information. the new AJAX 1.0 is now out and client side stuff is easer. I
have not finished my research on how to do this but searching on the tags for
AJAX like:

<asp:ScriptMana ger ID="ScriptManag er1" runat="server"
EnablePartialRe ndering=true >
<Scripts>
<asp:ScriptRefe rence />
</Scripts>
</asp:ScriptManag er>
The Scripts and asp:scriptrefer ence are the key I will post some urls with
the examples when I find them

Thank you for all the help
--
Jerry
"Laurent Bugnion [MVP]" wrote:
Hi,

Jerry C wrote:
Laurent,

Thank you for the reply. I would not have thought of the heartbeat solution.

I have found a article about client callbacks
http://msdn2.microsoft.com/en-us/library/aa479042.aspx

This article may help me program it. Examples are a good thing also if you
have them.

I still would like to find some examples of using the onunload events to
communicate to the server to close the session. Learning how to make browser
events trigger server code will help me in other situations.

Thank you

The major issue with onunload is that it should be also fired when the
browser is closed (using Exit, the "X" button, Alt-F4 or any other
method). However, in that case, the JavaScript engine may very well be
shut down before the XmlHttpRequest has a chance to be sent to the server.

Other events (onload, onresize...) are more reliable. However, having a
safe server-side application is always a good idea, because JavaScript
may be disabled... ;-)

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Feb 28 '07 #5

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

Similar topics

1
7997
by: Vetrivel | last post by:
Application architecture : Develop interface between two existing systems, a. Enterprise CRM system b. Web based intranet system. Environment : Intranet Server : IIS and ASP. Script : VBScript and Javascript Client : 1. IE browser. 2. VBForm embedded with WebBrowser control (MS Internet
0
1853
by: melledge | last post by:
Ajax Developers' Day to Kick Off XTech 2006 Conference Industry experts offer insight into next generation of the Web ALEXANDRIA, VIRGINIA, USA - April 25, 2006 - In response to the rapidly developing world of Ajax user interfaces on the browser, IDEAlliance (www.idealliance.org) announced today that its annual XTech Conference will kick off on May 16 with Ajax Developers' Day. XTech 2006 (www.xtech-conference.org), to be held May...
3
1085
by: Bob | last post by:
Hi, i want to use ajax in my application, but i saw there are a lot of possibilities. What to choose among clientcallback, atlas or ajax.net (anthem, magicajax) ? Thanks for advice (pro's / contra's) Bob
4
1069
by: Bob | last post by:
Hi, i want to use ajax in my application, but i saw there are a lot of possibilities. What to choose among clientcallback, atlas or ajax.net (anthem, magicajax) ? It seems that ajax.net is easy to install /use. Thanks for advice (pro's / contra's) Bob
4
2885
by: rgparkins | last post by:
Hello I am running out of time with a problem I have running PHP 5.04 and Apache 2.0 and really need help :(. I have a page that stores a variable in session but each time I reload that page the session seems to be re-created and is an empty array. I have checked the session file and the variable is being stored against the session id, but I dont know why PHP is not picking up the session after I reload.. I have tried the usual suspects...
13
4014
by: Marvin Zhang | last post by:
Hi, I'm not familiar with web programming, but I have a problem here. I have a page. When a user click one button on it, I will use AJAX to request a PHP script which will do a bunch of tasks, asynchronously. These tasks might take long time so I want to keep the user informed of the progress. The problem is that only the PHP script knows the progress, how can the web page gets these information from PHP script?
2
2231
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
I see a lot of posts claiming that you can use AJAX or Javascript to run some kind of "heartbeat" " server polling" that tells the server that the page is still open. I need to know how exactly to do this (server side and client side) or where I can find information on doing this. I want to run some code after a page is closed and I don't want to wait for the session timeout. if anyone has information please post explanations, code...
0
7199
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along the way. First, deep linking is not something that a completely AJAX web site should be able to do by it's very nature of everything being on one page basically. So how can a person deep link to something that is on one page? This question...
4
2057
by: KDawg44 | last post by:
Hi, I have a feeling this is a dumb question, but I am exploring AJAX and PHP. I would like to write my PHP in an Object Oriented approach. What is the limitation on what I can return in AJAX? Every example I find seems to be text, which make sense because it is client side. So, if I want to try to separate the presentation from the application, I should call a PHP script using AJAX, and in that PHP script have objects, call the...
0
9970
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
11207
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
10896
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
10443
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
7153
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
5830
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
6031
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4652
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
3
3259
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.