Creating Global.asa
To create the Global.asa, just use
notepad to create a file called Global.asa in your virtual directory or root
directory. Then we can get coding.
The Global.asa have 4 main
sections -
-
Application_onStart() - is
executed whenever an application begins.
-
Application_onEnd() - is
executed whenever an application stops.
-
Session_onStart() - executed
whenever a session beings.
-
Session_onEnd() - its amazing
how this one is executed when a session...... ENDS!
Lets actually create a Global.asa
now.
<script
language="VBScript" RUNAT="SERVER">
Sub Application_OnStart()
Set objConn = CreateObject("ADODB.Connection")
Set Application("objConn") = objConn
Set Application("stTime") = CStr(Now)
End Sub
Sub Application_OnEnd()
Set Application("objConn") = Nothing
Set objConn = Nothing
End Sub
Sub Session_OnStart()
Application.Lock
Application("visitors") = Application("visitors") + 1
Session("visitor") = Application("visitors")
Application.Unlock
End Sub
Sub Session_OnEnd()
End Sub
</script> |
This seems pretty straight forward -
- When the Application Starts - An
ADODB.Connection object is created and made an application variable of the
same name. The current time is stored as a string as well, in an application
variable.
- When the Application Ends - The
connection object gets set to nothing.
- When a Session Starts - We increment
the visitor counter by 1 and set that value to the application variable and
the session variable. We use Application.Lock and Unlock to make sure that
no-one else updates the value at the same time (things could get messy).
- When the Session Ends - Nothing
happens.
You can see that this can be used for some
things that you may do already, and things that you might find useful. Things
to keep note of - The <script> tags and the RUNAT="SERVER" property. Also, the
language doesn't have to be VBScript.