ASP Application_OnStart och Application_OnEnd-händelser
Definition och användning
Application_OnStart-händelsen
Application_OnStart-händelsen inträffar innan den första nya sessionen skapas (när Application-objektet för första gången hänvisas till).
Detta händelse läggas till i Global.asa-filen.
Kommentar:Användning av Session, Request eller Response-objekt i Application_OnStart-händelsens skript orsakar ett fel.
Application_OnEnd-händelsen
Application_OnEnd-händelsen inträffar vid applikationens slut (när webbservern stoppar att köra).
Detta händelse läggas till i Global.asa-filen.
Kommentar:MapPath-metoden kan inte användas i Application_OnEnd-koden.
Syntax
<script language="vbscript" runat="server"> Sub Application_OnStart ... End Sub Sub Application_OnEnd ... End Sub </script>
Exempel
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>
Show the number of current visitors in ASP files:
<html> <head> </head> <body> <p> There are <%response.write(Application("visitors"))%> online now! </p> </body> </html>