473,471 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Create 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 2702
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:ScriptManager ID="ScriptManager1" runat="server"
EnablePartialRendering=true >
<Scripts>
<asp:ScriptReference />
</Scripts>
</asp:ScriptManager>
The Scripts and asp:scriptreference 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
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 :...
0
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...
3
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 /...
4
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...
4
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...
13
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,...
2
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...
0
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...
4
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? ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
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.