| <!-- Declare instance of the ASPCounter component with application-level scope //--> <OBJECT ID=”ASPCounter” RUNAT=”Server” SCOPE=”Application” PROGID=”MSWC.Counters”> </OBJECT> <!-- Declare instance of the ASPContentLimk component with session-level scope //--> <OBJECT ID=”ASPContentLink” RUNAT=”Server” SCOPE=”Session” PROGID=”MSWC.NextLink”> </OBJECT> <SCRIPT LANGUAGE=”VBScript” RUNAT=”Server”> Sub Application_onStart() ‘Create an instance of an ADO Recordset with application-level scope Set Application(“ADOConnection”)= Server.CreateObject(“ADODB.Connection”) Dim varArray(3) ‘Create a Variant array and fill it VarArray(0) = “This is a” VarArray(1) = “Variant array” VarArray(2) = “stored in the” VarArray(3) = “Application object” Application(“Variant_Array”) = varArray‘Store it in the Application Application(“Start_Time”) = CStr(Now) ‘Store the date/time as a string Application(“Visit_Count”) = 0 ‘Set Counter variable to zero End Sub Sub Application_onEnd() Set Application(“ADOConnection”) = Nothing End Sub Sub Sesson_onStart() ‘Create an instance of the AdRotator component with session-level scope Set Session(“ASPAdRotator”) = Server.CreateObject(“MSWC.AdRotator”) Dim varArray(3) ‘Create a Variant arry and fill it VarArray(0) = “This is a” VarArray(1) = “Variant array” VarArray(2) = “stored in the” VarArray(3) = “Session object” Session(“Variant_Array”) = varArray ‘Store it in the Session Session(“Start_Time”) = CStr(Now) ‘Store the date/time as a string ‘We can access the contents of the Request and Response in a Session_onStart ‘event handler for the page that initiated the session. This is the *only* ‘place that the ASP page context is available like this. ‘as an example, we can get the IP address of the user: Session(“Your_IP_Address”) = Request.ServerVariables(“REMOTE_ADDR”) Application.Lock intVisits = Application(“Visit_Count”) +1 Application(“Visit_Count”) = intVisits Application.Unlock End Sub Sub Session_onEnd() Set Session(“ASPAdRotator”) = Nothing End Sub </SCRIPT> |
| Application(“variable_name”) = variable_value Application(“variable_name”) = variant_array_variable_name Set Application(“variable_name”) = object_reference |
| variable_value = Application(“variable_name”) variant_array_variable = Application(“variable_name”) Set object_reference = Application(“variable_name”) |
|
编辑推荐:ASP应用程序设计的Web状态管理分析 |
关注此文的读者还看过: