Wrox Programmer Forums
|
ASP Pro Code Clinic As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Pro Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 5th, 2005, 10:56 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

Sheela: One of obvious reasons why we can’t trust Session_onEnd is that there is no guarantee that the event will be triggered when the browser is closed or if the user simply moves on to visit another site without even logging out?!! .. hmm session would get killed automatically after 20 min (default).

ALEX_GRIM: You need to grow!! and more importantly learn the basics first before picking up a fight with somebody. AFAIK using caps means we are showing off our anger.

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
 
Old February 5th, 2005, 12:28 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I don't want to nit pick, but what Vadivel is saying isn't entirely true, so for future reference of this thread, let me clarify things once and for all.

The problem with closing the browser or navigating to another page is not that Session_OnEnd is not guaranteed to fire, but that it doesn't fire *at all*, ever. This is by design. There are basically three reasons why Session_OnEnd ever fires:

1. A timeout. The default timeout is 20 minutes. When a user hasn't visited another page in your application (because they closed their browser or navigated to another page) for the past 20 minutes, the session will time out. Just as with the other 2 options, you don't have access to regular Request and Response objects, because there *is* no request. There is no currently connected user associated with the Session_OnEnd event (although, of course, it fires for a specific user / session)

2. Explicit ending. Whenever you call Session.Abandon(), the Session_OnEnd will fire as well. Session.Abandon can be used to programmatically end a session, for instance on a log out page.

3. On a graceful application restart or shutdown. Whenever you close or restart IIS through the IIS Manager or through a server restart, each Session will be ended, invoking Session_OnEnd.
Note that this is not the case for crashing servers, crashing IIS or a power outage.

So, Session_OnEnd will *never* fire when you navigate to another page. Earlier in this thread I introduced a buggy workaround of manually calling Session.Abandon so Session_OnEnd is triggered, through the onunload attribute of the <body> tag. This is not a great solution, and therefore not very recommended.


Hope this clarifies things.....

Imar

---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old February 5th, 2005, 11:59 PM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

True Imar .. I was also trying to say the same thing .. that "Session_OnEnd" would never fire at all.

Might be I should have avoided saying "There is no gurantee" .. which might not have created this confusion :)

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
 
Old February 6th, 2005, 06:43 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yeah, I thought so. That's why I wanted to clarify things, because the "not guaranteed" could have caused more confusion than it solved.... ;)

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old February 15th, 2005, 01:49 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Imar,Vadivel,Sheela

For my asp page ,I use this script that call session_onEnd method(global.asa).
Since my Client Applications run on FullScreen Pop up window,i used this technique.

Will closing with main browser
It will give follwoing message
 The Web page you are viewing is trying to close the window
  Do you want to close this window?

Looking for your opinions too :)


<script>

function closeSession()
{
 //capturing ALT + F4
 if (event.altKey==true && event.keyCode==0 )
{
  //alert("closed1")
 document.location.href="SessionEndFile.asp";
   window.close();
  }

Xwidth=window.document.body.offsetWidth-window.event.clientX
YHeight=window.event.clientY
if(Xwidth<=30&&YHeight<0)
{
  // alert("closed2")
 document.location.href="SessionEndFile.asp";
   window.close();

}

}
window.onbeforeunload=closeSession

//or we can use body(unload) method

</script>

now simply "SessionEndFile.asp" is like

<% Session.Abandon %>



Cheers :)

vinod
 
Old February 16th, 2005, 03:11 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Vinod,

Try this trick:

http://vadivel.blogspot.com/2004/02/...nt-window.html

It doesn't work on all browsers (IE only, I think) but it might work for you....

Cheers,

Imar
 
Old February 17th, 2005, 08:01 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hi Imar
Thanks alott ,now my problem is solved !!!
Since before closing a window I am calling the sessionEndfile.asp ,which inturn call
Session .Abandon,
Now I ensure that the session_onEnd must be triggered when the browser is going to be closed :)

Cheers :)

vinod
 
Old May 3rd, 2005, 02:20 AM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default

lmmfao...... ok guys. look here.......
go to www.profiles.grimmusic.grimmusic.com, then click the "search / browse" link, then click "search by members ONLINE" link, then lake a look at the members you see online, later, go back. you will see different members.
that's because the session timed out and ENDED. i've had this working for over 3 months now, and i've NEVER seen it NOT work.... EVER.

the session timeout works on requests, when you make an initial request, you "start" a session, when you don't make a request after the specified amount of time, your sessions is "timed out". you create a variable in the OnStart event, and call it from the OnEnd event. you HAVE to do it JUST LIKE THAT, because the on end event really doesn't know who the hell you're talking about when you tell it to perform a certain action when a sessionID times out, because THERE IS NO sessionID to be talking about, it's ended, and dumped from the server's memory.

like i said, use my example, and set your timeout to 1 minuite, and unless your application is a shopping cart or something, keep it at one minuite. there really is no reason to have it any more than that, it's a waste of recources. if the client needs to continue the session, they simply make another request, and they're right back in there.

but remember, you must first store the client info you're going to be working with as a variable in the OnStart event, then call it from the OnEnd event. there is no other way to do this that I know of, but this DOES work, and has BEEN working for over 3 months. so you can argue with me about it, or you can just swallow your pride, and give it a shot.


---------------------------
A Black sheep moves easy in the darkness.
GRIM@GRIMMUSIC.COM
WWW.GRIMMUSIC.COM
 
Old May 3rd, 2005, 02:27 AM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default

Quote:
quote:Originally posted by quetzalcoatl

sub Session_OnEnd
    dim varUserName
    varUserName = Session("username")

    dim objDestroy
    set objDestroy = Server.CreateObject("Usuario.Sesion")
        objDestroy.destroySession(varUserName)
    set objDestroy = nothing
end sub

destroSession deletes a register in a database in Sybase, but how sheela writes ii doesn´t work, it does not fire, however i thougth in the unload event, any other suggestions?????
THAT IS BECAuse there is no longer an exsisting session to work with, it has ended (hence the OnEnd event being fired). now if you were to make that "varusername" an application variable in the OnStart event, you COULD call it from the on end event. but i'm not to sure about exactly what you're trying to achieve, but with my global.asax i'm creating a variable in th OnStart, then with that variable i'm updating a DB entry, then whith the OnEnd, i'm updating it again to say that thiey're offline.

---------------------------
A Black sheep moves easy in the darkness.
GRIM@GRIMMUSIC.COM
WWW.GRIMMUSIC.COM
 
Old May 3rd, 2005, 07:42 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

ALEX_GRIM - they still let you in this forum.

"A Black sheep moves easy in the darkness." mmmmm a black sheep you are. You are an insulting little smart ass.

Wind is your friend
Matt





Similar Threads
Thread Thread Starter Forum Replies Last Post
Session_OnEnd Question.... seananderson Classic ASP Basics 3 July 19th, 2007 03:54 PM
session_onend and databases scottlet Classic ASP Databases 2 May 30th, 2007 04:47 AM
help with session_onend chinedu Classic ASP Basics 8 October 26th, 2004 10:13 PM
Session_OnEnd v. SQL bluewater68 Classic ASP Professional 0 August 18th, 2003 04:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.