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

How to Destroy Session On Window Close ???

malav123
217 100+
Hi,
I am maintaning the status of users in database who are online... and also it makes false the status whenever user gets logout but my problem is that if user closes the window without logout at that time i want to change the status as a false... so how can i do this ??? i have tried many things but still i am not getting the desired things... It's only changes after Session timeout period... so please suggest me some solution... it's urgent need....

thanks...

-malav.
Apr 21 '08 #1
8 4001
Plater
7,872 Expert 4TB
You can do a number of things:
You can attempt to fire some sort of javascript even on UnLoad()
You can shorten the Session timeout (so it's much quicker)
You can make the Session timeout VERY short and implement a heartbeat on every page to keep the session active.
Apr 21 '08 #2
shweta123
692 Expert 512MB
Hi,

Please refer this Article regarding your question.
Apr 21 '08 #3
malav123
217 100+
Hi,

Please refer this Article regarding your question.


Hi shweta,
I have already used that article's concept but it only gives the alert i.e. "Killing the session", it does not affect the session abandon method.... and that's why it also doesn't affect the code that i have write in global.asax for change the status of active users... so where is the problem ??? pls reply...
Apr 23 '08 #4
shweta123
692 Expert 512MB
Hi,

Please see if this Article helps you
Apr 23 '08 #5
Plater
7,872 Expert 4TB
You will need to write that event. On the closing events in javascript you would fire off an xmlhttprequest call to your server to a special page that just abandon's the session (like say a logout.aspx page)
Apr 23 '08 #6
malav123
217 100+
You will need to write that event. On the closing events in javascript you would fire off an xmlhttprequest call to your server to a special page that just abandon's the session (like say a logout.aspx page)


Sorry but i am not getting properly what you are suggesting.... so please explain me again what to do ???
Apr 24 '08 #7
malav123
217 100+
Hi,

Please see if this Article helps you

Thanks shweta for response but i have reffered this link also... but still i have not got solution in that link...
Apr 24 '08 #8
Frinavale
9,735 Expert Mod 8TB
Thanks shweta for response but i have reffered this link also... but still i have not got solution in that link...
Plater had the right idea in suggesting the OnUnload JavaScript Event. The problem is when that happens the page is already unloaded and you can't make a call to the server.

Instead you should use the OnBeforeUnload JavaScript event to make a call back to the server and log out the user.

Expand|Select|Wrap|Line Numbers
  1. window.onbeforeunload = function()
  2. {
  3.      //here you make your call to the aspx page to log out the user
  4.      //make sure you don't return anything or else the user will be prompted to make a decision as to whether or not they want to actually leave the page....
  5. }
  6.  
This will log out the user as soon as the close the window or leave the webpage.
Just be aware that all of your full page post backs to the server will cause the page to be unloaded. This means that you should probably add another JavaScript function to "register" the controls for valid postbacks.

Eg

Expand|Select|Wrap|Line Numbers
  1. var _validPostback = false;
  2. function RegisterValidPostBack()
  3. {    _validPostback=true;}
  4. window.onbeforeunload = function()
  5. {    if(_validPostback==true)
  6.      {
  7.          //here you make your call to the aspx page to log out the user
  8.          //make sure you don't return anything or else the user will be prompted to make a decision as to whether or not they want to actually leave the page....
  9.      }
  10. }
  11.  
In your Server Side code you will have to add the onclick JavaScript event to each control that posts back..

eg
Expand|Select|Wrap|Line Numbers
  1.    myButton.Attributes.Add("onclick","RegisterValidPostBack();")
  2.  

-Frinny
Apr 24 '08 #9

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"...
9
by: ScooterMX | last post by:
I have a <a href="javascript:top.window.close()"><img src="exit.gif"></a> tag on my page that closes itself when you click on it. What I NEED is for it to put up a confirmation message that...
10
by: Shang Wenbin | last post by:
Hi, When I want to close the current window using window.close() in IE6.0, there will be a confirm box that: The web page you are viewing is trying to close the window. Do you want to close this...
1
by: dibyendu_k | last post by:
Hi, There is a problem i cant solve regarding Internet Explorer 5.5. It is regarding the Print Dialog Box. From a webpage if I open a popup window (window.open()) containing buttons Print and...
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...
1
by: BennyVK | last post by:
Hi, I'm not sure if this question should go to the "JavaScript" section; but I'm open to non-JavaScript (like VBScript) options too. So, I'm posting this here. I have the following problem:...
7
by: Toccoa | last post by:
After considerable googling - I mean searching with Google(r) - I could not find javascript on a button or <a href=... to close a window in the latest versions of IE and FireFox. There seemed...
2
by: teixeira | last post by:
Hello, I'm using a 3rd part DLL via Add reference i my C# project and sometimes the DLL generate a messagebox with an error and an OK button. I would like to know if its possible to...
1
by: mmr315 | last post by:
how to destroy session when browser closed with out logout.pls hlp me
2
by: kurt sune | last post by:
Hello, I have a weird problem, I hope someone can explain this for me. I have a webpage using masterpage. In it I create a popup window using this code: Dim js As String = "<script...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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...

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.