/* ------------------- ASP document reference set -----------------------*/
* --> Author: Crawler
* --> Time: 2007-4.28---2007-4.30)
* --> Contact: caolvchong@gmail.com
* --> Document function:
1. I reviewed ASP and deepened my understanding of ASP structure and ASP experience.
2. It can be used for ASP reference and self-written for reference.
This is the second part: ASP seven objects
/* ----------------------------- Seven ASP objects ----------------------------*/
* --> Application object:
Function: in a given application Program Shared information among all users and persistent storage during server running
In addition, the application object also provides methods to control access to application layer data and can be used
Events that trigger the process at the time of Start and Stop (onstart events and onend events)
Property: no built-in property exists.
Set: Custom Attributes
Set and description of application objects:
Contents: all variables (and
A set of values, including the variant array and the reference of the variant type object instance.
Staticobjects: all variables stored in the Application object defined by the <Object> element
A set of (and their values)
Example:
Set the application property value:
Application ("myvar") = "hello"
Set Application ("myobj") = server. Createobject ("mycomponent ")
Method:
Contents. Remove (): removes an application set.
Contents. removeall (): removes all application sets.
Lock (): prevents other customers from modifying the variables stored in the Application object to ensure that only
One customer can modify and access the application variable. If the user does not explicitly call the unlock
After the. asp file ends or times out, the server removes the lock on the Application object.
Set
Unlock (): allows other clients to modify
The variable in this object. If this method is not explicitly called, the web server ends or times out at the end of the. asp file.
Then unlock the Application Object
An example of a comprehensive point:
In 1. asp:
'Set three application property values
Application ("chong1") = "1st application set items"
Application ("chong2") = "2nd application set items"
Application ("chong3") = "3rd application set items"
'All set attribute values are retained in application. contents, and the base number starts from 0. Therefore, you can use
'For Loop read
'Here we will summarize the attributes of the contents set:
'Count property: returns the number of all items in the set. The returned value is an integer.
'Item attribute: Used to set or return the value of a specific member in a set. The item attribute is
Contents
'Default attribute of the set, so. Item (X) is equivalent to. (x)
'Key property: Key (x) returns the corresponding property name, as shown in the preceding figure.
Application. Contents. Key (1)
'Will return chong1
For I = 1 to application. Contents. Count
Response. Write (application. Contents. Item (I ))
Next
In 2. asp:
'2. asp and 1. asp share the content of the application object, so you can repair the elements of this set.
Change or delete
Application ("chong1") = "I was modified" 'modify the application Attribute Value
Application. Contents. Remove ("chong2") 'deletes the application property value
For each J in application. Contents 'for each access application
Response. Write (application. Contents. Item (j ))
Next
Events: For the summary of the Global. ASA files, such as onstart () and onend (),
Experience: Generally, when you want to modify an application value, you should first lock it with lock (), and then modify and repair it.
Unlock () after modification to prevent multiple users from accessing the object concurrently
Frequently used: Set, modify, and delete application sets, combined with the lock and Unlock methods
* --> Session object:
Function: the session object stores the information required by a specific user session. When a user redirects between pages of an application
The variables stored in the session object are not cleared, and when you access the page in an application
The variable always exists. When the user requests a web page from the application, if the user does not have a session
The Web server automatically creates a session object. When the session expires or is abandoned, the server terminates
Session (the difference between session and application is that session is not shared. each user has its own session.
Can be used to verify the user's identity)
Set: like the application, the session has two sets: Contents and staticobject.
Attribute:
CodePage: read/write. Integer. The definition used to display page content in the browser Code Page (code page). Code
The page is the numeric value of the character set. Different Languages and places may use different code pages. For example, 650001
Yes UTF-8, 936 is gb2312
Lcid: read/write. Integer. defines the page Region ID (lcid) sent to the browser. lcid is the unique identifier
For example, 2057 defines that the currency symbol of the current region is 'region'. lcid.
For formatcurrency and other statements, as long as there is an optional lcid parameter. lcid can also be
ASP Processing Instruction <%... %>, and takes precedence over the settings in the lcid attribute of the session.
Sessionid: Read-Only. Long Integer. The session identifier of the returned session. sessionid attribute returns the user's
Session ID. When creating a session, the server will generate a separate ID for each session. Session tag
Returns the Data Type of a persistent integer. In many cases, sessionid can be used for web page registration.
Statistics
Timeout: read/write. Integer. defines the timeout period in minutes for this session.
If no page is refreshed or requested during the specified period, the session ends. You can repair the page as needed.
Change. The default value is 20 min. The time should be shorter for sites with high usage.
Method:
Abandon (): The abandon method deletes all objects stored in the session object and releases
Source. If you do not explicitly call the abandon method, the server will delete these objects once the session times out.
When the server finishes processing the current page, the following example releases the session Status
In addition, session, like application, has contents. Remove () and
Contents. removeall () method
Events: For the summary of the Global. ASA files, such as onstart () and onend (),
Frequently-used: Set, modify, and delete sessions. In addition, timeout is also commonly used. Remember that sessions depend on cookies. When the browser is closed or does not
Session cannot be accessed when Cookie is supported
* --> Request object:
Function: retrieves the value that the client browser sends to the server during an HTTP request.
Set:
Clientcertificate: used to indicate an identity to the server when the client accesses a page or other resources.
All fields or entries of the customer certificate. Each member is only
Read. clientcertificate collection to obtain the verification field from the web browser publishing request (by X.509
Standard). If the web browser uses the SSL3.0/pct1 protocol (that is, it uses
URL starting with https: //, instead of http: //) to connect to the server and server for request verification, the browser
Verification fields will be sent. If verification is not sent, the clientcertificate set will return empty. Required
You must configure the Web server to require client verification before using clientcertificate
Set.
Cookies: a set of the values of all cookies sent by the user system based on users' requests. These cookies are only
Valid for the corresponding domain. Each member is read-only, and cookies also have three attributes: Count, item, and key.
Usage can be analogous to the application mentioned above. In addition, cookies also have an attribute.
Haskeys: indicates whether the cookie is multi-value or single-value. If multiple values are returned, true is returned. If a single value is returned, false is returned.
When the form: attribute value is post
Set. Each member is read-only. form also has three attributes: Count, item, and key.
Querystring: The name/value pair attached to the URL of the user request or
If the method property value is get (or its attribute is omitted), the string is subject to question mark (?) Specify the value after, or
The value of all HTML control units in <form>. Each member is read-only, and querystring also has
Three attributes: Count, item, and key
Servervariables: the HTTP header value sent along with the client request, and several types of web servers
A set of environment variable values. Each member is read-only and servervariables also has
The servervariables parameters of the count, item, and key attributes are printed on "servervariables ".
The parameter set is in
Attribute:
Totalbytes: Specifies the total number of bytes sent by the client in the Request body. This attribute can only be read
Method:
Binaryread (): obtains the data transmitted from the client to the server as part of the POST request.
Obtain the data from the client and store it in safearray. safearray is an array, where
It contains the dimension and boundary information. Generally speaking, a security array is an array determined by the number of dimensions and the upper and lower limits of dimensions.
The binaryread method is used to read unprocessed data sent from the client as part of the POST request.
The method is used to access data at the underlying layer. In contrast, the request. Form set is used to view the information sent in the announcement request.
Once binaryread is called, any variable in the reference request. Form set will
An error occurs. Otherwise, once a variable in the request. Form set is referenced
Binarywrite will also cause errors. Remember, if you do not specify
Determines the subset of the variable, searches for the request. Form set, and enforces the above rules.
Commonly used: For Form submission or parameter transfer between pages, the request plays an important role and is well differentiated.
Difference between form and querystring,
When only request is used, ASP will automatically adjust the two sets, but this is not good for tables.
Single, usually the request is through
The name of the form element to obtain the value of the form element)
In addition, when no component uploads a file, totalbytes is used to obtain the size of the uploaded file, binaryread ()
Used to obtain all the content of the upload form.
Of course, if you want to obtain the file content, you need to analyze and intercept the content obtained by binaryread ().
* --> Response object:
Function: sends the output to the client, which is opposite to the request.
Set:
Cookies: In the current response, all cookie values of the client are returned.
Example:
'Expires set the expiration event, in the format of # The date of the English month word number, 4-digit year #
Response. Cookies ("name") = "crawler"
Response. Cookies ("name"). expires = # May 11,2007 #
'Request. Cookies will be used for reading.
Name = request. Cookies ("name") 'so that the name gets the "crawler"
'Using cookies, you can perform password-free logon to determine whether a user has logged on and the events triggered by these events.
And so on
'Cookie also has the count, item, and key attributes.
'There are also dimain, haskeys, path, and secure attributes for a single cookie. The specific attributes will be checked later.
Attribute:
Buffer = true | false: read/write, Boolean, indicating whether the output created by an ASP page is always stored
In the IIS Buffer, until all server scripts on the current page are processed, or the flush and end methods are
This attribute must be set before any output (including HTTP header information) is sent to IIS. Therefore
In the. asp file, this setting should be followed by the first line of the <% @ Language =... %> statement. asp3.0
The buffer is set to true by default, and the buffer is set to false by default in earlier versions)
Cachecontrol: read/write, writable. Set this attribute to "public" to allow the proxy server to cache pages,
If it is "private", the proxy server cache is prohibited.
Charset: read/write, character type, attached to the HTTP Content-Type Header created by the server for each response
Name of the character set used on (for example: ISO-LATIN-7)
Content type = "mime-type": read/write, response type, indicating the HTTP content type of the response, standard mime
Type (for example, "text/XML" or "image/GIF"). If omitted, the MIME type is used.
"Text/html", the content type tells the browser the type of the expected content, about the mime list, printed in
In the mime reference document, you can refer
Expires: read/write, numeric type, indicating the time length of the page in minutes.
The same page before the expiration of the validity period will directly read the content displayed in the buffer. After the validity period, the page
The interface is no longer stored in the private (User) or public (proxy server) buffer. If you want a file
Terminate. You can set this attribute value to a very large negative number.
The expires attribute uses the earliest time/date as the end time of the file (a relative time)
Expiresabsolute: read/write, date/time type, indicating the absolute day when a page expires and is no longer valid
Period and time. If the user returns to this page before the expiration date, the cached page is displayed. If not specified
The homepage expires at midnight on the same day. If no date is specified, the homepage is specified on the day when the script runs.
Expiration Date
Isclientconnected: Read-only, Boolean, returns the status flag of whether the customer is still connected to and downloading the page.
Before the current page has been executed, if one customer moves to another page, this flag is available
To abort the processing (use the response. End method)
Pics: Write-only and protocol-type. Create a PICS header and add it to the HTTP header in the response.
Define the vocabulary level in the page content, such as violence, sex, and bad language
Status: read/write, encoding type, indicating that the error or page processing is
Status values and information about the success. For example, "200 OK" and "404 Not found"
Method:
Addheader "name", "content": Creates a custom HTTP
Header, and added to the response. The existing headers with the same name cannot be replaced. Once you have added one
Headers cannot be deleted. This method must be sent to any page (text and HTML)
Pre-user use
Appendtolog ("string"): When the "W3C extended Log File Format" file format is used
Add an entry to the log file of the Web server requested by the user. At least the entry must be included in the site containing the page.
On the "extended properties" Page, select "URI stem". string to add to the log file.
Because fields in IIS logs are separated by commas, this string cannot contain commas (,).
(,). The maximum length of a string is 80 characters.
Binarywrite (): Write the variable-type safearray in the current HTTP output stream without passing through
Any character conversion. For writing non-string information, such as the number of binary requests for custom applications
Data or binary bytes that constitute an image file.
Clear (): When response. buffer is true, the existing buffer page is deleted from the IIS Response Buffer.
But does not delete the HTTP Response Header. You can discard partially completed pages.
End (): Let ASP end the script for processing the page, return the currently created content, and then discard any
Further Processing
Flush (): Send all the current buffer pages in the IIS buffer to the client (send the output in the buffer immediately). When
When response. buffer is true, it can be used to send part of the content of a large page to individual users.
If response. buffer is not set to true, this method will cause a runtime error.
Redirect ("url") sends an "302 Object Moved" HTTP header in the response, indicating
The browser downloads the corresponding address Page Based on the string URL, and redirects the browser to the URL.
Write ("string"): Write the specified characters in the current HTTP response information stream and IIS Buffer
Is part of the returned page. This value cannot contain character combinations. If necessary, escape sequences can be used.
When processing the script, the web server also enters the conversion sequence in another format.
Output: <% =... %>, but the conversion between ASP and HTML slows down. The best way is to keep a line
Response. Write (), commonly used for string & connection: cookies, buffer, content type,
Expires, status, binarywrite, clear, end, flush, redirect, and write are all very
Cookies are commonly used to interact with browsers. Cookies are used for customer identities.
Expires; buffer and clear, flush, and end related to buffer are used for caching.
Content type is most commonly used for the output of XML and image content; stutas is used to determine the status,
Especially in XMLHTTP; write is used for output; Redirect is used for transfer content; binarywrite is generally
Used to receive uploaded file content
* --> Server Object:
Function: provides access to methods and attributes on the server. Most of the methods and attributes are used as utility functions.
Able to serve
Attribute:
Scripttimeout: integer. The default value is 90 seconds. The script for setting or returning the page is executed after the server exits and
The time (in seconds) that can be executed before an error is reported. When this value is reached, page execution is automatically stopped,
And delete the pages that contain errors that may enter the endless loop from the memory or those that are waiting for other
Web page of the resource. This prevents the server from being overloaded due to incorrect pages.
This value needs to be increased.
Method:
Createobject ("identifier"): creates an object identified by identifier (a component, Application
Or a script object), returns a reference that can be used in the code.
The application (Global. Asa page) is used to create objects at the Session Layer or within the scope of the application layer.
It is identified by its classid, such as "{CLSID: BD96C556-65A3...37A9}" or a progid string
For example, "ADODB. Connection", we usually use progid
Note the following:
1. By default, the object created by the server. Createobject method has a page scope. This is
After the current ASP page is processed, the server will automatically destroy these objects.
2. You can destroy an object by setting the variable to nothing or a new value.
3. You cannot create an object instance with the same name as a built-in object.
Execute ("url"): stops the execution of the current page and transfers the control to the webpage specified in the URL.
The previous environment (session Status and current transaction status) is also passed to the new web page,
Control passed back to the original page, and continue to execute the statement after the execute Method
Getlasterror (): returns a reference to the ASP asperror object, which contains the reference of this page in ASP
Detailed data of the last error occurred during processing. The information provided by the asperror object
Htmlencode ("string"), including file name, row number, and error code: returns a string
The string is a copy of the input value string, but all illegal HTML characters are removed,
Common illegal HTML characters and their conversion characters include:
<Corresponding <
> Correspondence>
& Corresponding &
"Corresponding"
(Space)
? (Copyright)
? Corresponding (registered trademark)
× × (Multiplication number)
Region corresponds to the region (except number)
Mappath ("url"): returns the complete physical path and file name of the file or resource specified in the URL.
Transfer ("url"): stops the execution of the current page and transfers the control to the page specified in the URL. the user's current environment (session Status and current transaction status) is also passed to the new page. unlike the execute method, when
When the new page is executed, the execution process ends instead of returning to the original page.
Urlencode ("string"): returns a string, which is a copy of the input value string,
All invalid characters in,
Common and invalid URL characters and their conversion characters include:
# Used to mark the specific document LOCATION % 23
% Encode special characters % 25
& Separate different variable value pairs % 26
+ Space % 2B in the variable value
/Indicates the directory path % 2f
\ Indicates the directory path % 5c
= Used to connect keys and values % 3d
? Start % 3f of the query string
Space % 20
. Period % 2e
: Colon % 3A
* --> Asperror object:
Due to the error mechanism, IIS has been able to identify and locate the problem, so it cannot go further.
* --> objectcontext object:
function: Controls ASP transaction processing. transaction reason Microsoft Transaction Server (MTS) management
event:
ontransactionabort: triggered by a abandoned Transaction Processing Event. After the script is processed,
ontransactioncommit: triggered by successful transaction processing events, after the script is processed
method:
setabort: explicitly discard a transaction
setcomplete: overwrite any previous call to objectcontext. call the setabort method
as it is not involved, you only need to know more about it.