HighTechTalks DotNet Forums  

How to end a session immediately when the browser closes?

ASP.net Caching microsoft.public.dotnet.framework.aspnet.caching


Discuss How to end a session immediately when the browser closes? in the ASP.net Caching forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
news.microsoft.com
 
Posts: n/a

Default How to end a session immediately when the browser closes? - 02-01-2005 , 03:28 AM






Hi everyone,

Sorry for cross-posting this message. My mistake.

I need some help (may be in the form of some sample code) for the subject
question.

I have an ASP.NET/C# application. I need to do quite a few tasks when the
session ends. I don't want to depend on the session timeout factor since it
may end too soon or it may hang around too long. I can't find any event
that fires when the browser closes. The Session_End event handler in the
Global.asax does not execute until the timeout value expires. Also, when it
does execute the Session_end, it seems that the session has already ended
and so, I have no access to any of the session variables I was holding onto.

Can anybody tell me the server side sequence of events and their handlers
that get called when the user closes a browser? Does the browser inform the
server that it is closing, so that I can do my cleanup?

Any help is highly appreciated.

Babu.




Reply With Quote
  #2  
Old   
Alvin Bruney [MVP]
 
Posts: n/a

Default Re: How to end a session immediately when the browser closes? - 02-01-2005 , 06:59 AM






There is no such event. What are you trying to accomplish? Maybe there is an
alternative approach. As far as the architecture is concerned, when the
server doesn't hear from the client after a given amount of time, it assumes
the client went away and initiates cleanup by firing the session end event.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://tinyurl.com/27cok
----------------------------------------------------------


"news.microsoft.com" <babupalladium1 (AT) yahoo (DOT) com> wrote

Quote:
Hi everyone,

Sorry for cross-posting this message. My mistake.

I need some help (may be in the form of some sample code) for the subject
question.

I have an ASP.NET/C# application. I need to do quite a few tasks when the
session ends. I don't want to depend on the session timeout factor since
it
may end too soon or it may hang around too long. I can't find any event
that fires when the browser closes. The Session_End event handler in the
Global.asax does not execute until the timeout value expires. Also, when
it
does execute the Session_end, it seems that the session has already ended
and so, I have no access to any of the session variables I was holding
onto.

Can anybody tell me the server side sequence of events and their handlers
that get called when the user closes a browser? Does the browser inform
the
server that it is closing, so that I can do my cleanup?

Any help is highly appreciated.

Babu.






Reply With Quote
  #3  
Old   
Jens Blom
 
Posts: n/a

Default Re: How to end a session immediately when the browser closes? - 02-01-2005 , 10:00 AM



Hi try this

<body onunload="doLogout()".......


<script language="javascript">
function doLogout()
{
var foo = new Image();
foo.src= 'yourLogoutPage.aspx?userId=someUserId';

}
<script>


this works
only one thing
it fires on refresh to

but ur users vill learn not to push refresh

or u can use xmlhttp or httpXml
cant remember witch gos first

sorry for the bad english

Regards
/Jens Blom





"news.microsoft.com" <babupalladium1 (AT) yahoo (DOT) com> wrote

Hi everyone,

Sorry for cross-posting this message. My mistake.

I need some help (may be in the form of some sample code) for the subject
question.

I have an ASP.NET/C# application. I need to do quite a few tasks when the
session ends. I don't want to depend on the session timeout factor since it
may end too soon or it may hang around too long. I can't find any event
that fires when the browser closes. The Session_End event handler in the
Global.asax does not execute until the timeout value expires. Also, when it
does execute the Session_end, it seems that the session has already ended
and so, I have no access to any of the session variables I was holding onto.

Can anybody tell me the server side sequence of events and their handlers
that get called when the user closes a browser? Does the browser inform the
server that it is closing, so that I can do my cleanup?

Any help is highly appreciated.

Babu.



Reply With Quote
  #4  
Old   
news.microsoft.com
 
Posts: n/a

Default Re: How to end a session immediately when the browser closes? - 02-03-2005 , 03:16 PM



Thanks for the input guys!

I understand that when the timeout kicks in, you could do the necessary
cleanups in the Session_End. But I still find it a little bit surprising
that the browser does not somehow inform the server from which the page was
fed, that it is closing or the user has navigated out of the site. I would
rather like to do the cleanup and end the session immediately once the user
has closed the browser or moved on to some other website.

Babu.

"news.microsoft.com" <babupalladium1 (AT) yahoo (DOT) com> wrote

Quote:
Hi everyone,

Sorry for cross-posting this message. My mistake.

I need some help (may be in the form of some sample code) for the subject
question.

I have an ASP.NET/C# application. I need to do quite a few tasks when the
session ends. I don't want to depend on the session timeout factor since
it
may end too soon or it may hang around too long. I can't find any event
that fires when the browser closes. The Session_End event handler in the
Global.asax does not execute until the timeout value expires. Also, when
it
does execute the Session_end, it seems that the session has already ended
and so, I have no access to any of the session variables I was holding
onto.

Can anybody tell me the server side sequence of events and their handlers
that get called when the user closes a browser? Does the browser inform
the
server that it is closing, so that I can do my cleanup?

Any help is highly appreciated.

Babu.






Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.