ASP » Session » OnEnd

The OnEnd event occurs when the Session quits. The signal of this event will run a handler script in the Global.asa file, if the script exists.

The Session_OnEnd event occurs when the Session ends. Normally, a Session is ended by being timed-out, either by default or by using Session.TimeOut, or by being abandoned by using Session.Abandon. The Session_OnEnd event is simply a subroutine with a reserved name that is placed in the Global.asa file. The code in the event cannot affect the user because he has quit the site.

In the example, there is no output because the user is already gone. The first line must specify the script language.

Note, only the Application, Server, and Session built-in objects are available from within the OnEnd event handler.

Examples

Code:
-------------------Global.asa--------------------------
<script Language="VBScript" RUNAT=Server>
Sub Application_OnEnd()
End Sub
 
Sub Application_OnStart()
Application("NumSession") = 0
Application("NumVisited") = 0
End Sub
 
Sub Session_OnEnd()
Application("NumSession") = Application("NumSession") - 1
End Sub
 
Sub Session_OnStart()
Application("NumSession") = Application("NumSession") + 1
Application("NumVisited") = Application("NumVisited") + 1
End Sub 
</script>
 
-------------------File1.asp----------------------------
Response.Write "You are " & Application("NumSession") & " of " & Application("NumVisited") & " users."

See Also: