A. Application
Share information within an application
You can use the application object to share information among all visitors to the application. The application corresponds to the application created in IIS.
B. Request
Obtain client input information
You can use the request object to obtain any messages sent from the client, including the post. Get method, cookies, and parameters transmitted by the client certificate from the HTML form. You can also access the binary data sent to the server, for example, upload.
C. Response
Send messages to clients
You can use the response object to control the information sent to the client, including sending the information directly to the browser, redirecting the browser to another URL or setting the cookie value.
D. Server
Local server operations
You can access methods and attributes on the server. Commonly Used: server used to create COM components. the Createobject method applies URL or HTML encoding to strings, maps virtual directories to physical paths, and sets the script timeout period.
E. Session
Stores session information for a single user
The Session object can be used to store the information required for a specific session. When a client accesses the server, a session is created. When a user redirects to a different page of the application, the variables stored in the session object will not be lost. The variables will be retained during user access to the application. You can also explicitly end the session and set the timeout period for idle sessions.
F. objectcontext
Transaction Processing
You can use the objectcontext object to submit or abort events started by ASP scripts.
G. asperror
Error Message
You can use the asperror object to capture ASP errors and return detailed error descriptions to users.
A: Application Object
It is usually used to implement the following functions
A.1 Store application-level global variables
A.2 locking and unlocking global variables
A.3 website counters
Contained sets, methods, and events
Type Name Description
---------------------------------------------------------------
The Set contents does not use the set of all variables stored in the Application object defined by the <Object> element.
Can be abbreviated as: Application ("numvisits") to application. Contents ("numvisits ")
Staticobjects uses the <Object> element to define a set of all variables stored in the Application object.
Method contents. Remove generic element to delete the specified variable stored in contents
Contents. removeall delete all variables stored in contents
Lock the variables stored in the application and cannot be modified by other customers. It is set to unlock or unlocked after execution on this page.
Unlock manually deletes the lock on the application variable
The event application_onend is declared in global. Asa and triggered when the application is executed for the first time.
Application_onstart is declared in global. Asa and triggered when the application ends.
Note:
1. When storing objects in the Application object, you still need to use the set parameter. You can directly call the application object to call its method.
2. The effect of calling the lock method is accumulative. That is, when you call the lock several times, you need to call the unlock several times to unlock the lock.
3. built-in objects cannot be stored in application objects.
4. arrays stored in application cannot be referenced directly by subscript.
5. Do not store the connection object of the database in the application.
B: request object
It is usually used to implement the following functions
B .1 obtain URL parameters
B .2 read the data passed in the form
B .3 read cookie data
B .4 read server environment variables
B .5 upload files
Included sets, methods, and attributes
Type Name Description
---------------------------------------------------------------
Set the clientcertificate client certificate set (SE 'tifikit)
Set of all cookies sent by cookies
The value of the form Element submitted by the form customer. The variable name is the same as the name attribute of the element in the form.
The value in the querystring URL parameter. If the method attribute of form is "get", all form element names and values are automatically added to the URL parameter.
Servervariables predefined server Variables
**************************************** ************************
Total number of bytes in the body of the HTTP request sent by the totalbytes Client
The binaryread (count) method obtains the Count byte data from the data submitted by the client and returns an unsigned array.
Note:
1. If the queried variables do not exist in the preceding five sets, empty is returned.
2. Specify the set name during query.
When a variable exists in more than one set, the server will retrieve the variable to be found and returned in the set in the order:
Querystring
Form
Cookies
Clientcertificate
Servervariables
3. There are two limitations when using request. Form:
3.1 can only accept a small amount of data (when the number of data bytes submitted by form is greater than kb, it cannot be used)
3.2request.form and request. binaryread cannot be used at the same time; otherwise, an error occurs.
4. Try not to use server Variables
5. Avoid using unqualified request objects
C: Response object
It is usually used to implement the following functions
C.1 output content to the client (webpage)
C.2 webpage redirection (use server. Transfer whenever possible)
C.3 write cookie
C.4 download an object
Included sets, methods, and attributes
Type Name Description
----------------------------------------------------------------
Set cookies to set the client cookie value. If the specified name does not exist, it is created. Otherwise, it is updated.
Whether the attribute buffer enables caching. This statement must be placed in the first line of the ASP file. After it is enabled, it is output to the client only after all scripts are executed.
Cachecontrol: sets whether the proxy server can buffer ASP and buffer levels.
Charset sets set the character set, for example, gb2312 in simplified Chinese. It works the same as charset = gb2312 In the meta tag on the webpage.
Contenttype: Set HTTP content type: text/html
Expires sets or returns the validity period of a page buffer in the browser, in minutes (IKS 'paie)
Expiresabsolute sets the absolute expiration time of page Buffering in the browser
Isclientconnected
Lcid sets or obtains the display format of the date, time, or currency.
Status sets the return status of the server, in the format of a three-digit plus Brief Description: response. Status = "401 unauthorized"
The addheader (headername, headervalue) method adds additional information to the HTTP header. The headername can be repeated. Once the information is added, it cannot be deleted.
Appendtolog manually adds a log to the Web server
Binarywrite writes data that does not undergo any character conversion to the HTTP output stream, which is used by various clients to send images or download files.
Clear Buffer
End stops processing ASP files and outputs the current results to the customer.
Flush sends buffered content to the client immediately
Redirect sends a redirection message to the browser. After receiving the message, the browser redirects to the specified page.
Write writes a string to the HTTP output stream.
Note:
1. To make the website internationalized, we recommend that you explicitly set the codePage attribute. The order in which the system looks up the codePage is:
Response. codePage
Session. codePage
Page @ codePage command
Set the metabase attribute aspcodepage in the virtual directory
When none of the preceding settings are set, the default value is ANSI.
2. When response. End is called, response. Flush is automatically called to send the existing content in the cache to the client. If you do not want this, you can call response. Clear to clear the cache first.
3. note response. redirect Only sends a redirection message to the browser. the browser sends a new request to the server based on the URL in the message because there are two round trips between the browser and the server, which reduces the efficiency, and the user's waiting time is extended. We recommend that you use server. transfer, which directly transfers processing to another page without sending another request
4. You cannot call the response. Redirect method after outputting some content to the client.
5. Use the flush method when there are many outputs
6. Try to use server. Transfer instead of response. Redirect
7. Use codePage to make the website internationalized
D: Server Object
It is usually used to implement the following functions
D.1 create a component instance
D.2 obtain the physical properties of the server
D.3 encode strings in HTML Format
D.4 turn to execute other ASP files
Included methods and attributes
Type Name Description
-----------------------------------------------------------
The scripttimeout attribute sets the script timeout. When an ASP page is not executed within the script timeout period, ASP terminates the execution and displays a timeout error.
Method Createobject: Create an instance of a server component. If this component implements the onstartpage and onendpage methods, onstartpage is executed when Createobject is created.
Execute is used to execute an ASP file. The executed ASP file is considered as part of the ASP file that currently calls the execute method.
Getlasterror returns an asperror object to describe the error details. Note that this method takes effect only after some data is sent to the client.
Htmlencode converts the output HTML string to HTML encoding, for example, <p> output: & lt; P & gt;
Mappath maps the virtual directory to an absolute path, for example, access database. To prevent downloading, place it outside the application. In this way, find the absolute path of the database on the server.
Transfer stops executing this ASP file and turns to executing another ASP file. If you want to use this method instead of the response. Redirect method, you need to call response. Clear to clear the buffer before calling transfer.
Urlencode encodes the output string
Note:
1. both the execute and transfer methods do not clear the content output from the current page to the buffer but directly turn to the execution of another page. The difference is that after the execution of execute, the following statement will be returned to continue to be executed, transfer will discard the following statement
2. The most common ones are Createobject and mappath.
E: Session Object
It is usually used to implement the following functions
E.1 stores information related to an access
E.2 set the access code page, Date Format
E.3 process access start and end events
Contained set, method, attribute, and event
Type Name Description
---------------------------------------------------------------
The contents set uses the script command (with MGA value statement) to store data in the session. You can omit contents and directly access the data, for example, Session ("Var ")
Staticobjects uses the <Object> tag to define a set of variables stored in the session object. It cannot be deleted during running.
Attribute codePage: Set the code page of the current session. Refer to the codePage attribute of the response object.
Lcid sets the display format of the date, time, or currency of the current session. For more information, see lcid attribute of the response object.
Sessionid: Unique Identifier of the returned session
Timeout: sets the session timeout period in minutes. The default value is 20 for IIS.
Method abandon: When ASP is executed, the variables stored in the session are released. During the next access, a session object is restarted. If this method is not explicitly called, only when the session times out will the variables in the session be released
Contents. Remove Delete the specified variable in the contents set
Contents. removeall delete all variables in the contents set
Event session_onend is declared in global. Asa. triggered when the customer first accesses or calls abandon.
Session_onstart is declared in global. Asa and triggered when session times out or abandon is called.
Note:
1. session. after abandon is called, the variables stored in the session on this ASP page can still be used until the next request, that is, access to the next ASP page, takes effect. At this time, the sessionid value has changed, the session_onstart process is executed again.
When session. Abandon is used to call server. Execute and server. Transfer, the variables in the session are still valid because they occur in the same request.
2. The contents. removeall method is used to delete all the variables in the contents set. It works instantly and does not discard the current session object (abandon), that is, the sessionid remains unchanged in the next request.
3. The session object often uses variable access, for example, Session ("username") = strname
F: objectcontext object
It is usually used to implement the following functions
F.1 discard a transaction ASP
F.2 accept one-person transaction ASP
Included methods and events
Type Name Description
-----------------------------------------------------------------
Method setabort discard the current transaction
Setcomplete this method only indicates that the transaction can be continued, and you do not have to discard it. It is not accepted immediately. Only when the execution of this file is complete, or all components involved in this transaction call setcomplete, accept this transaction
Event ontransactionabort is triggered when this transaction is abandoned
Ontransactioncommit is triggered when this transaction is accepted
Note:
1. To use this transaction mechanism or objectcontext on an ASP page, you must add <% @ transaction = required %> at the beginning of the file.
2. You only need to call the objectcontext. setabort method once to discard the transaction.
3. Generally, you do not need to explicitly call setcomplete because ASP accepts transactions after executing this ASP file if setabort is not called by default.
4. The ontransactionabort and ontransactioncommit processes must be stored in the same file as ASP.
G: asperror object
It is usually used to implement the following functions
Included attributes
Type Name Description
------------------------------------------------------------------
Attribute aspcode returned error code
Number returns the com standard error code
Source returns the source code of the Error. If yes, the number of rows can be returned.
CATEGORY returns a string indicating the error type, for example, IIS error or script error.
File name with an error
Line where an error occurs
Column where an error occurs
Description error description
Aspdescription if this error is related to ASP, a more detailed error description is returned.
Ado native class
ADO provides some built-in classes and methods for establishing a connection with the database, and then perform the following operations on the database: add, delete, modify, and query.
A: Connection connection class
This class has the following features:
A.1 establish database connection
A.2 Execute SQL statements
A.3 execute transactions
Attributes and Methods
Type Name Description
--------------------------------------------------------------------
Attribute connectionstring connection string, which needs to be set before opening the connection
Connectiontimeout time-out period, which must be set before connection
Mode connection mode, which must be set before connection
Cursorlocation: set or return the cursor position
Defaultdatebase specifies a default database for the connection
Isolationlevel determines the transaction isolation level on the connection
Provider specifies a driver for the connection, which can be included in connectionstring
Version: returns the version of ADO.
Method open to establish a connection
Close interrupts a connection.
Execute execute commands and SQL statements on the connection
Begintrans
Committrans
Rollbacktrans
Error message returned by the object Error Data Source
Note:
1. Description of the cursorlocation attribute:
Aduseserver: It can reflect changes on the database server at any time, but the system overhead is very high.
Aduseclient: no real-time performance. You can sort and filter databases.
If you do not need real-time data, try to use aduseclient to improve performance.
Note:
1. Use the connection pool to use the ole db driver
2. Enable and close later: create a connection before use, close immediately after use, and release the object
3. Never put the connection in application or session
4. If no result set is returned, add adexecutenorecords to the execute parameter.
B: Command command class
This class has the following features:
B .1 pre-compiled SQL statements
B .2 Execute SQL statements
B .3 execute the Stored Procedure
B .4 return the content of the entire table
Includes attributes, methods:
Type Name Description
---------------------------------------------------------------------------
Attribute activeconnection associates a command line Object with an opened connection
Commandtype specifies the command type
Commandtext defines the content of a command line, for example, an SQL statement.
Commandtimeout specifies the time for the server to wait for a command to be executed.
Execute the command line and return a DataSet object (recordset)
Note:
1. both the connection and command classes have their own execute methods and can be used to execute an SQL statement. In this respect, the difference between the two is not big, but the command class is more powerful, you can specify the commandtype attribute and perform other operations such as stored procedures.
Note:
1. properly set the commandtype attribute to improve execution efficiency. We do not recommend that you use adcmdunknow.
2. If no record set is returned, add adexecutenorecords to the commandtype attribute.
3. If you need to execute an SQL statement of type 4 repeatedly, You can pre-compile it first, which improves the efficiency.
C: recordset dataset class
This class has the following features:
C.1 store search results
C.2 manipulate data, add, delete, and modify data
C.3 sort data again
Includes attributes, methods:
Type Name Description
-----------------------------------------------------------------------
Attribute recordcount returns the number of records in the record set
How locktype locks a dataset
Cursortype the cursor type in the record set
Bof/EOF returns whether the current position of the cursor in the record set is the header or tail of the record set.
Movenext/movepre
Movefirst/movenext move the cursor of the record set to the beginning or end
Note:
1. Value of the locktype attribute:
*************************************
Adlockreadonly = 1. The default value indicates that the record set is opened in read-only mode,
Therefore, data cannot be changed. In this case, an error occurs when addnew is used.
Adlockpessimistic = 2, sequential record locking (one by one ),
This method is used to lock the data source immediately when the update method is called. At this time, other users cannot access this data.
Adlockoptimistic = 3, open record lock (..),
The record is locked only when the update method is called.
Adlockbatchoptimistic = 4, open batch update,
Used to update data in batches. It corresponds to the updatebatch method.
2. Value of the cursortype attribute:
************************************
Adopenforwardonly = 0, default value, only forward cursor
You can only scroll forward in records to save resources and improve performance.
Adopenstatic = 3, static cursor
It can be used to find the static copies of data or the set of records that generate reports. In addition, the addition, deletion, and change operations made to other users are invisible.
----------------------------------
/* It is recommended that only the above two cursors be used in ASP */
--------------------------------
Adopenkeyset = 1, key set cursor
The cursor is different from the static cursor 4. The only difference is:/prohibit viewing Records added by other users, prohibit access to records deleted by other users, and other changes made by other users are still visible.
Adopendynamic = 2, Dynamic Cursor
The addition, modification, and deletion operations made by other users are displayed, allowing all types of movement in the record set.
Note:
1. Set the value of locktype reasonably. If you only view the result, set it to adlockreadonly.
2. Set the value of cursortype reasonably. If only movenext is used, set it to adopenforwardonly.
3. If you do not have requirements on real-time data, try to use aduseclient
4. recordcount is valid only when cursortype is set to adopenkeyset or adopenstatic.
Microsoft COM Component
Microsoft has created a considerable number of COM components that developers can use in their applications for free. Most of the components are developed for the setup of many applications. For example: ADO (ActiveX Data Object), which is just a collection of COM objects, collaborating with us to access the database
In addition to ADO, Microsoft also provides a large number of practical COM components for ASP. You can view the list of installed COM components supporting ASP in IIS:
Component list
Component Name Description
----------------------------------------------------------------------------------
Ad rotator provides a random banner rolling system
Content linker can create a display table for the content page of the relevant URL set, and also provides the navigation function to access the relevant URL in sequence.
Content rotator randomly displays text or HTML code on the webpage
Browser capabilities is a utility used to detect the browser functions used by visitors. For example, determine whether the visitor's browser supports VBScript, ActiveX control, and other information on the server.
Counters is used to record the number of clicks on a webpage, allowing visitors to understand the access volume of a page
Permission checker is used to determine whether a user has permissions to access a file or directory. This function is particularly useful when the basic or NT challenge/response password verification system is enabled.
Myinfo traces the Web server information of an object. The myinfo component can trace a series of website information, such as the web administrator, company or organization name, address, and phone number.
Tools is an excellent tool to complete basic server-side tasks.
To learn more about the properties and methods of these components, visit: http://msdn.microsoft.com/library/psdk/iisref/comp275c.htm