Latest web development tutorials

ASP Application_OnStart and Application_OnEnd event

Application Object Reference Complete Application Object Reference

Application_OnStart event

Application_OnStart event occurs before the first new session is created (when the Application object is first referenced).

This event is placed in the Global.asa file.

Note: When referencing Session, Request or Response object Application_OnStart event script throws an error.

Application_OnEnd event

Application_OnEnd event occurs at the end of the application (when the web server is down).

This event is placed in the Global.asa file.

Note: MapPath method can not be used Application_OnEnd code.

grammar

<script language="vbscript" runat="server">

Sub Application_OnStart
. . .
End Sub

Sub Application_OnEnd
. . .
End Sub

</script>


Examples

Global.asa:

<script language="vbscript" runat="server">

Sub Application_OnEnd()
Application("totvisitors")=Application("visitors")
End Sub

Sub Application_OnStart
Application("visitors")=0
End Sub

Sub Session_OnStart
Application.Lock
Application("visitors")=Application("visitors")+1
Application.UnLock
End Sub

Sub Session_OnEnd
Application.Lock
Application("visitors")=Application("visitors")-1
Application.UnLock
End Sub

</script>

ASP file is displayed in the current number of visitors:

<html>
<head>
</head>
<body>
<p>
There are <%response.write(Application("visitors"))%>
online now!
</p>
</body>
</html>


Application Object Reference Complete Application Object Reference