w3pop.com :: 网络学院 :: ASP :: ASP Application_OnStart 与 App
The Application_OnStart event occurs before the first new session is created (when the Application object is first referenced).
Application_OnStart 事件在第一个新的session建立之前产生(当Application对象被第一次引用时)。
This event is placed in the Global.asa file.
该事件是写在Global.asa文件中的。
Note: Referencing to a Session, Request, or Response objects in the Application_OnStart event script will cause an error.
注意:直接在Application_OnStart事件中引用Session、Request、Response对象将会导致错误产生。
The Application_OnEnd event occurs when the application ends (when the web server stops).
Application_OnEnd事件在application结束后产生(当网络服务器停止时)。
This event is placed in the Global.asa file.
该事件是写在Global.asa文件中的。
Note: The MapPath method cannot be used in the Application_OnEnd code.
注意:绝对路径(MapPath)方法不能在Application_OnEnd代码中使用。
<script language="vbscript" runat="server"> Sub Application_OnStart . . . End Sub Sub Application_OnEnd . . . End Sub </script> |
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> To display the number of current visitors in an ASP file: <html>
<head>
</head>
<body>
<p>
There are <%response.write(Application("visitors"))%>
online now!
</p>
</body>
</html>
|
评论 (0)
All