An Application object is an application-level object used to share information among all users and maintain data permanently during web application running.
Application attributes:
The method is as follows:
The application object does not have built-in properties, but we can create its own properties.
<% Application ("property name") = Value %>
In fact, most Application variables are stored in the contents set. When you create a new application variable, you actually add one in the contents set. The following two scripts are equivalent:
<% Application ("greeting") = "Hello! "%> Or <% application. Contents (" greeting ") =" Hello! "Because the application variable exists in the Set, if you want to display it all, the method has been used multiple times, for example, for each loop.
<%
For each item in application. Contents
Response. Write ("<br>" & item & application. Contents (item ))
Next
%>
Application Method:
The application method has only two methods: Lock and unlock. The lock method is used to ensure that only one user can operate on the application at the same time. Unlock is used to cancel the lock method restriction. For example:
<%
Application. Lock
Application ("visitor_num") = Application ("visitor_num") + 1
Application. Unlock
%>
Application Event:
1. application_onstart ()
Triggered when the event application starts.
2. application_onend ()
This event is triggered when the application ends.
The two event processes must be defined in the Global. asp file. Generally, the function that connects data is defined in these two events and then stored in global. asp. For example:
Sub application_onstart
Application ("tt18_connectionstring") = "driver = {SQL
Server}; server = Jeff; uid = sa; Pwd =; database = test"
End sub
An array can be defined as an application object. However, this array can only be saved as an object, and its value cannot be retrieved using application (0. You can define a temporary array to implement this function. For example:
<%
Dim array ()
Array = Application ("array ")
For I = 0 to ubound (array)
Response. Write array (I)
Next I
%>
You can also modify the application object to define a temporary array, assign the application object to the array, modify the elements of the array, and then assign the array back to the application object. For example:
<%
Dim array ()
Array = Application ("array ")
Array (0) = "Jeff"
Array (1) = "zhu"
Application. Lock
Application ("array") = Array
Application. Unlock
%>
Objectcontext object
This object is used to control the transaction processing of Active Server Pages. The reason for the transaction is Microsoft Transaction Server (MTS) management.
Event
Objectcontext. ontransactionabort
Triggered by a abandoned Transaction Processing Event, which occurs after the script completes processing.
Objectcontext. ontransactioncommit
Triggered by successful transaction processing events, after the script completes processing.
Method
Objectcontext. setabort
Explicitly discard a transaction.
Objectcontext. setcomplete
Overwrite any previous call to call objectcontext. setabort.
Request object
The request object is used to accept all information in all requests sent from the browser to your server.
Set
Request. clientcertificate (Key [subfield])
A set of information about all customer certificates. For a key, the set has the following keywords:
Subject
The topic of the certificate. Contains all information about the certificate receipt. Can be used with all subdomain suffixes.
Issuer
The issuer of the certificate. Contains all information about certificate verification. Except CN, it can be used with all subdomain suffixes.
Vadidfrom
The date on which the certificate is issued. Use Vbscript format.
Validuntil
The time when the certificate is not valid.
Serialnumber
The serial number of the certificate.
Certificate
The binary stream that contains the entire certificate content, in ASN.1 format.
For subfield, the subject and issuer keywords can have the following subdomain suffixes: (for example, subjectou or issuerl)
C
Country of origin.
O
Company or organization name.
Ou
Organizational unit.
CN
The general name of the user.
L
Local.
S
State (or province ).
T
The title of an individual or company.
GN
Name.
I
Initial.
When the file cervbs. Inc (used by VBScript) or cerjavas. Inc (used by jscript) is included in your Active Server Page through the # include orientation, the following two flags can be used:
Cecertpresent
Specifies whether the customer Certificate exists. Its value is true or false.
Ceunrecongnizedissure
Specifies whether the issuer of the last certificate in the linked list is unknown. Its value is true or false.
Request. Cookies (cookie [(key). Attribute])
Cookie set. Allows you to obtain the cookie of a browser. Cookie indicates the cookie that is returned. Key is used to return the cookie value with a certain keyword from the cookie dictionary. For attribute, you can use the attribute haskeys to determine whether a cookie has a subkeyword. The value of haskeys is true or false.
Request. Form (parameter) [(INDEX). Count]
The set of all the data in the HTML form. Parameter is the name of an element in an HTML form. Index is used when a parameter has more than one value (for example, when the multiple attribute is used in <SELECT>. When a parameter has multiple values, count indicates the number of multiple values.
Request. querystring (varible) [(INDEX). Count]
Queries the set of all values of a string. Varible is the name of a variable in the query string. If a variable has more than one value, index is used. When a parameter has multiple values, count indicates the number of values.
Request. servervaribles (server environment variable)
Set of environment variables. The HTTP header can be read. You can use the HTTP _ prefix to read any header information. For example, http_user_agent accepts the client proxy HTTP header (browser type ). In addition, you can use the variables shown in the following table to obtain any environment information.
All_http
All HTTP headers sent by the client have the prefix HTTP _.
All_raw
All HTTP headers sent by the client have the same results as those sent by the client without the prefix HTTP _
Appl_md_path
The metadatabase path of the application.
Appl_physical_path
The physical path corresponding to the application metadatabase path.
Auth_password
The password entered in the Password dialog box when the Basic Authentication mode is used.
Auth_type
When a user accesses a protected script, the server is used to verify the user's authentication method.
Auth_user
The authenticated user name.
Cert_cookie
The unique ID of the customer certificate.
Cert_flag
Customer certificate flag. If there is a client certificate, bit0 is 0. If the client certificate verification is invalid, bit1 is set to 1.
Cert_issuer
The issuer field in the user certificate.
Cert_keysize
Number of digits of the Secure Socket Layer connection keyword, such as 128.
Cert_secretkeysize
The number of digits that the server verifies for a private keyword. For example, 1024.
Cert_serialnumber
The serial number field of the customer certificate.
Cert_server_issuer
Issuer field of the server certificate
Cert_server_subject
The topic field of the server certificate.
Cert_subject
The topic field of the client certificate.
Content_length
The length of the content sent by the client.
Content_type
The Form Content or http put data type sent by the customer.
Gateway_interface
The gateway interface used by the server.
HTTPS
If the request passes through the Secure Channel (SSL), on is returned. If the request comes from an insecure channel, return off.
Https_keysize
Number of digits of the Secure Socket Layer connection keyword, such as 128.
Https_secretkeysize
The number of digits that the server verifies for a private keyword. For example, 1024.
Https_server_issuer
The issuer field of the server certificate.
Https_server_subject
The topic field of the server certificate.
Instance_id
The ID of the IIS instance.
Instance_meta_path
The metabase path of the IIS instance that responds to the request.
Local_addr
Returns the server address that receives the request.
Logon_user
The user logs on to the Windows NT account
Path_info
The path provided by the client.
Path_translated
The Path obtained by ing from virtual to physical.
QUERY_STRING
Query string content.
Remote_addr
The IP address of the remote host that sends the request.
Remote_host
The name of the remote host that sends the request.
Request_method
Request Method. Such as get, Head, and post.
Script_name
Name of the script to be executed.
Instance_id
The ID of the IIS instance.
Instance_meta_path
The metabase path of the IIS instance that responds to the request.
Local_addr
Returns the server address that receives the request.
Logon_user
The user logs on to the Windows NT account
Path_info
The path provided by the client.
Path_translated
The Path obtained by ing from virtual to physical.
QUERY_STRING
Query string content.
Remote_addr
The IP address of the remote host that sends the request.
Remote_host
The name of the remote host that sends the request.
Request_method
Request Method. Such as get, Head, and post.
Script_name
Name of the script to be executed.
SERVER_NAME
The host name, DNS address, or IP address of the server.
Server_port
The Port Number of the server that receives the request.
Server_port_secure
If the server port receiving the request is a security port, the value is 1. Otherwise, the value is 0.
Server_protocol
The name and version of the protocol used by the server.
Server_software
Name and version of the server software that responds to the request and runs the gateway.
URL
Provide the basic part of the URL.
Method
Request.BinaryRead(Count)
Receives unprocessed content from an HTML form. When this method is called, count indicates the number of bytes to receive. After this method is called, count indicates the number of bytes actually received.
Attribute
Request.TotalBytes
Length of the query body, in bytes
Response object
The response object is used to send data to the client browser. You can use this object to send server data to the client browser in HTML format. It and request form a pair of objects for receiving and sending data, this is also the basis for dynamic implementation. The following describes common attributes and methods.
1. Buffer attributes
This attribute is used to specify whether a buffer is used for page output. The default value is false. If this parameter is set to true, the result is output to the browser only after the entire Active Server Page is executed. For example:
<% Response. Buffer = true %>
<HTML>
<Head>
<Title> buffer example </title>
</Head>
<Body>
<%
For 1 to 500
Response. Write (I & "<br> ")
Next
%>
</Body>
</Html>
When this page is executed, all content of the entire home page will be displayed in the browser at the same time. This home page will exist in the cache until the script execution ends.
2. expires attributes
This attribute is used to set the duration (unit: minute) of the browser cache page and must be refreshed on the server side. Use the following settings:
<% Response. expires = 0%>
By adding this line of code to the ASP file, each request is required to refresh the page, because the response will expire as soon as it receives the page.
3. Write Method
This method sends data to the client browser, for example:
<% Response. Write "Hello, world! "%>
4. Redirect Method
This method allows the browser to locate another URL. In this way, when the client sends a Web request, the browser type of the client has been determined, and the client is relocated to the corresponding page. For example:
<HTML>
<Head>
<Title> redirect example </title>
</Head>
<Body>
<Form aciton = "formjump. asp" method = "Post">
<Select name = "wheretogo">
<Option selected value = "fun"> Fun </option>
<Option value = "news"> News </option>
<Option value = "sample"> sample </option>
</SELECT>
<Input type = submit name = "jump" value = "jump">
</Form>
</Body>
</Html>
The above is the submitted form. The following is the formjump. asp file for processing the form:
<% Response. Buff = true %>
<HTML>
<Head>
<Title> redirect example </title>
</Head>
<Body>
<%
Thisurl = "http://www.tinyu.com /";
Where = request. Form ("wheretogo ")
Select case where
Case "fun"
Response. Redirect thisurl & "/Fun/default. asp"
Case "news"
Response. Redirect thisurl & "/news/default. asp"
Case "sample"
Response. Redirect thisurl & "/sample/default. asp"
End select
%>
</Body>
<HTML>
In this example, after the user selects the application, press the "jump" button to submit the form. After receiving the application, the server calls formjump. asp to locate the corresponding URL. However, you must note that the HTTP title has been written to the client browser, and any changes to the HTTP title must be made before the page content is written. In this case, you can do the following:
After the file starts <@ Language = ..>, write:
Response. Buffer = true
Set at the end:
Response. Flush
Here, flush is a method of response. It must be used only when the buffer attribute is set to true. Otherwise, a running mode error occurs. Another clear method is used to clear cached pages. It can only be used when the buffer attribute is set to true.
5. End Method
This method is used to notify the active server to stop processing ASP files when this method is used. If the buffer attribute of the response object is set to true, the end method sends the content in the cache to the customer and clears the punch zone. Therefore, to cancel all outsourcers to the customer, you can clear the buffer and then use the end method. For example:
<%
Response.buffer=true
On error resume next
Err.clear
if Err.number<>0 then
Response.Clear
Response.End
end if
%>
Server Object:
The server object provides access to methods and properties on the server. Most of the methods and attributes serve as functions of the utility.
Syntax
Server. Property | Method
Attribute
Scripttimeout:
The scripttimeout attribute specifies the maximum time that a script can run before it ends. When processing server components, the timeout limit will no longer take effect.
Syntax server. scripttimeout = numseconds
Numseconds
Specifies the maximum number of seconds that a script can run before the end of the server. The default value is 90 seconds.
Note
You can use the aspscripttimeout attribute in metadatabase to set the default scripttimeout value for Web Services or web servers. The scripttimeout attribute cannot be set to smaller than the value specified in the metabase. For example, if numseconds is set to 10 and metabase is set to 90 seconds, the script times out after 90 seconds. However, if numseconds is set to 100, the script times out after 100 seconds.
For more information about using metadatabase, see about metadatabase.
In the following example, if the server processes the script for more than 100 seconds, it will time out.
<% Server. scripttimeout = 100%>
The following example obtains the current value of the scripttimeout attribute and stores it in the variable timeout.
<% Timeout = server. scripttimeout %>
Method
Createobject
Create an instance of the server component by using the Createobject method. If this component executes the onstartpage and onendpage methods, the onstartpage method is called. For more information about server components, see ASP components that can be installed.
Syntax server. Createobject (progid)
The progid parameter specifies the type of the object to be created. The progid format is [Vendor.] component [. version].
Note by default, the object created by the server. Createobject method has a page scope. This means that after the current ASP page is processed, the server will automatically destroy these objects. To create an object with a session or application scope, you can use <Object> to mark and set the scope attribute of the session or application, or store the object in the dialog and Application variables.
For example, in the following script, when the session object is destroyed, that is, when the conversation times out or the abandon method is called, the objects stored in the session variable are also damaged.
<% Set session ("ad") = server. Createobject ("mswc. adrotator") %>
You can destroy an object by setting the variable to nothing or a new value, as shown below. The first example releases the ad object, and the second example uses a string to replace the ad object.
<% SESSION ("ad") = nothing %>
<% SESSION ("ad") = "Other valum" %>
You cannot create an object instance with the same name as a built-in object. For example, the following script returns an error.
<% Set response = server. Createobject ("response") %>
Example <% set myad = server. Createobject ("mswc. adrotator") %>
In the preceding example, A mswc. adrotator server component named myad is created. The mswc. adrotator component can be used to automatically rotate advertisements on Web pages.
For more information about server components, see creating components for ASP.
The htmlencode method applies HTML encoding to the specified string.
Syntax server. htmlencode (string)
The string parameter specifies the string to be encoded.
Sample script <% = server. htmlencode ("the paragraph Tag: <p>") %>
Output the paragraph Tag: <p>
Note that the above output will be displayed as the paragraph tag by the web browser: <p> if you check the source file or open a web page in text mode, you can see the encoded HTML.
Mappath
The mappath method maps the specified relative or virtual path to the corresponding physical directory on the server.
Syntax
Server. mappath (PATH)
Parameters
Path
Specifies the relative or virtual path of the physical directory to be mapped. If the path starts with a forward slash (/) or backslash (/), the mappath method regards the path as a complete virtual path when returning the path. If the path does not start with a slash, The mappath method returns the path relative to the existing path in the. asp file.
Note
The mappath method does not support relative path syntax (.) or (..). For example, the following relative path ../mydir/myfile.txt returns an error.
The mappath method does not check whether the returned path is correct or whether it exists on the server.
Because the mappath method only maps paths regardless of whether the specified directory exists, you can first map the paths of the physical directory structure with the mappath method, it is then passed to the component that creates the specified directory or file on the server.
Example
For the example below, the data.txt file and the test. asp file containing the following scripts are all in the directory c:/inetpub/wwwroot/script. C:/inetpub/wwwroot directory is set as the host directory of the server.
The following example uses the server variable path_info to map the physical path of the current file. Script
<% = Server. mappath (request. servervariables ("path_info") %> <br>
Output
C:/inetpub/wwwroot/script/test. asp <br>
Because the path parameters in the following example do not start with a slash, they are relatively mapped to the current directory, where C:/inetpub/wwwroot/script. Script
<% = Server. mappath ("data.txt") %> <br>
<% = Server. mappath ("script/data.txt") %> <br>
Output
C:/inetpub/wwwroot/script/data.txt <br>
C:/inetpub/wwwroot/script/data.txt <br>
The following two examples use the slash character to specify the full virtual path of the returned path on the server. Script
<% = Server. mappath ("/script/data.txt") %> <br>
<% = Server. mappath ("/script") %> <br>
Output
C:/inetpub/script/data.txt <br>
C:/inetpub/script <br>
The following example shows how to use a forward slash (/) or backslash (/) to return the physical path of the home directory. Script
<%= server.mappath("/")%><BR>
<%= server.mappath("/")%><BR>
Output
C:/inetpub/wwwroot <br>
C:/inetpub/wwwroot <br>
Urlencode
The urlencode method applies the URL encoding rules, including escape characters, to the specified string.
Syntax
Server. urlencode (string)
Parameters
String specifies the string to be encoded.
Example
Script <% response. Write (server. urlencode ("http://www.tinyu.com";) %>
Output HTTP % 3A % 2f % 2 fwww % 2 etinyu % 2 ECOM
Session Object
Session refers to the period from when a visitor arrives at a specific homepage to when the visitor leaves. Each visitor obtains a session independently. In a web application, when a user accesses the application, the session type variable allows the user to share data on all pages of the web application; if another user accesses the web application at the same time, the user also has his own session variables, but the two users cannot share information through the session variables, the application type change allows multiple users on the site to share information across all pages.
1. sessionid attributes
This attribute returns the unique identifier of the current session and assigns a different number to each session.
I encountered user control problems during the development process. The function is to implement a module for a website. When a member logs on to this module and another user logs on with the same member name, the module cannot be viewed. That is to say, a member name can only be viewed by one person at the same time. I implement control by using the member name (assumed as userid, unique) and sessionid. When a member logs on, a session is sent to the member to record the logon status, for example, Session ("status") = "logged", and the session. sessionid of the member is written to the database. When he wants to browse this module, he first checks whether he is logged on. If he has logged on, he checks whether his sessionid is the same as that recorded in the database. If not, he cannot access it. In this way, when another user logs on with the same member name, the database records the new sessionid. The former cannot pass the check when accessing this module. This enables a single member name to be viewed by only one person at the same time. This feature has a special effect on some paid websites. It prevents a member name from being browsed by multiple users and safeguards the company's interests.
2. Timeout attribute
This attribute defines the time limit of the user session object. If the user does not refresh the webpage within the specified time, the session object will be terminated. The default value is 20 minutes.
3. Abandon Method
This method is the only method for session objects. It can be used to clear session objects, eliminate user session objects, and release their occupied resources. Example: <% session. Abandon %>
4. session_onstart and session_onend events
Like the application, the session_onstart event is triggered every time the object's routine is started, and the processing process of the session_onstart event is run. That is to say, when the server receives an HTTP request from a URL in the application, this event is triggered and a session object is created. Similarly, this event must be included in the Global. Asa file.
When the session. Abandon method is called or is not refreshed within the timeout time, this triggers the session_onend event and then runs the script. Session variables are associated with specific users. The session variables assigned to a user are completely independent of the session variables of other users and will not affect each other.
Session application column:
Like the application, an array defined as the session type can only take the entire array as an object. You cannot directly change the value of an element in the session array. To create a session array, you must first define a common array, assign an initial value to each of its elements, and finally define it as a session array. For example:
<%
Dim array ()
Array = array ("Li", "Ming", "male ")
Session ("info") = Array
Response. Write SESSION ("info") (0 )&"-"
Response. Write SESSION ("info") (1 )&"-"
Response. Write SESSION ("info") (2) & "<br>"
%>
<HR>
<%
Array (0) = "day"
Array (1) = "yu"
Array (2) = "male"
Session ("info") = Array
Response. Write SESSION ("info") (0 )&"-"
Response. Write SESSION ("info") (1 )&"-"
Response. Write SESSION ("info") (2) & "<br>"
%>