Recommended: Some ASP codes worth collecting Some ASP codes worth collecting Some ASP codes worth collecting 1. oncontextmenu=window.event.returnvalue=false will completely block the right mouse button table border oncontextmenu=return(false)tdno/table can be used for Table 2. body onselectstart=return false Cancel select
In order to be able to use properly, they must be placed in a virtual application on the server and the provided global.asa file must be placed in the root directory of the application. The easiest way is to put the global.asa file into the root directory of the default web site (by default, C:/InetPub/WWWRoot).
Rename any existing global.asa file is a good way to restore the file later.
1. Display the contents of the Application collection
The ASPCounter object is a member of the StaticObjects collection (defined by the <OBJECT> element), but the rest (instified by the Server.CreateObject) are members of the Contents collection.
You can see the values placed in these collections using the global.asa example webpage, which has been seen before:
The following is the quoted content: <!-- Declare instance of the ASPCounter component with application-level scope //--> <OBJECT ID=ASPCounter RUNAT=Server SCOPE=Applicatoin PROGID=MSWC.Counters> </OBJECT> ... ... <SCRIPT LANGUAGE=VBScript RUNAT=Server> Sub Application_onStart() 'Create an instance of an ADO Connection 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 thd Application Application(Start_Time) = CStr(Now) 'Store the date/time as a string Application(Visit_Count) = 0 'Set counter variable to zero End Sub ... ... </SCRIPT> |
(1) Code to traverse Contents collection
To traverse the Contents collection, a For Each ... Next structure can be used. Each item in the set can be a simple Variant type variable, a Variant array, or a reference to an object. Because different processing is required for each type of value, each type has to be checked to determine its type.
This work can be done using the VarType function in VBScript. Here IsObject and IsArray functions are used instead:
The following is the quoted content: For Each objItem in Application.Contents If IsObject(Application.Contents(objItem)) Then Response.Write Object reference: ' & objItem & ' ElseIf IsArray(Application.Contents(objItem)) Then Response.Write Array: ' & objItem & ' contents are: VarArray = Application.Contents(objItem) 'Note: the following only works with a one-dimensional array For intLoop = 0 To UBound(varArray) Response.Write Index( & intLoop & ) = & _ VarArray(intLoop) & Next Else Response.Write Variable: ' & objItem & ' = _ & Application.Contents(objItem) & End If Next |
Note how the program retrieves the array from the Application object. Assign it to a local variable, using the following statement:
varArray = Application.Contents(objItem)
Use the UBound function to find out the size of the array (number of elements), and this value can be used as the termination condition of the traversal:
For intLoop = 0 UBound(varArray)
This example is a one-dimensional array and will only display the contents of such an array. Code can be edited as needed to handle multidimensional arrays, for example:
The following is the quoted content: For intLoop = 0 To UBound(varArray) IntNumberOfDimensions = UBound(varArray, 1) For intDimension = 0 To intNumberOfDimensions Response.Write Index( & intLoop & ) = _ & varArray(intLoop, intDimension) Next Response.Write Next |
(2) Code to traverse the StaticObjects collection
The StaticObjects collection contains all object references declared using <OBJECT> elements in global.asa. Because each entry is an object variable, you can use simpler code to traverse this array. We will output the name of the object (original definition in the ID attribute):
The following is the quoted content: For Each objItem in Application.StaticObjects If IsObject(Application.StaticObjects(objItem)) Then Response.Write <OBJECT> element: ID= ' & objItem & ' End If Next |
Share: Common syntax of 11 databases in ASP programming This article mainly introduces the common syntax for ASP connections to 11 databases. For details, please refer to the following: 1. DSN-less connection method of Access database: The following is the referenced content: set adocon=Server.Createobject(adodb.connection) adoconn.OpenDriver={Microsoft Access Driver(*.mdb)}; DBQ= _ Server.MapPath
2 pages in total Previous page 12 Next page