ASP built-in object

Source: Internet
Author: User
Tags servervariables

1. Request object
You can use the request object to access all information transmitted Based on HTTP requests, including parameters, cookies, and user authentication transmitted from HTML tables using the post or get methods.
Request [. Set | attribute | method] (variable)
1. Form
The form set retrieves the values of the table elements sent to the HTTP Request body by using the POST method.

Request. Form (element) [(INDEX) |. Count]

Element specifies the name of the table element to be retrieved from the set.
An optional index parameter. You can use this parameter to access one of multiple values of a parameter. It can be any integer between 1 and request. For (parameter). Count.
Number of elements in the count set

The form set is indexed by the parameter names in the Request body. The value of request. Form (element) is an array of all element values in the Request body. Call request. Form (element). Count to determine the number of values in the parameter. If the parameter is not associated with multiple values, the count is 1. If no parameter is found, the count is 0. To reference a single value in a table element with multiple values, you must specify the index value. The index parameter can be any number from 1 to request. Form (element). Count. If you reference one of multiple table parameters without specifying the index value, the returned data is a string separated by commas.

2. querystring
The querystring collection retrieves the value of the variable in the HTTP query string. The HTTP query string is composed of question marks (?) Specify the value after.

Request. querystring (variable) [(INDEX) |. Count]

The querystring collection allows you to retrieve the QUERY_STRING variable by name. The value of request. querystring (parameter) is an array of the values of all parameters in QUERY_STRING. You can call request. querystring (parameter). Count to determine the number of parameters.

3. Cookies

A cookie is actually a tag. When you access a Web site that uniquely identifies your website, it will leave a tag on your hard disk, the next time you visit the same site, the website page will look for this tag. Each web site has its own tag, and the TAG content can be read at any time, but it can only be completed by the page of the site. The cookies of each site and the cookies of all other sites exist in different files in the same folder (you can find them in the cookie folder under the Windows directory ). A cookie is a tag that uniquely identifies a customer. A cookie can contain information shared by all pages of a Web site during a conversation or between dialogs, you can also use cookies to exchange information between pages. The cookie set provided by the request allows the user to retrieve the cookie value sent in the HTTP request.

Request. Cookies [(key) |. Attribute]

Cookie specifies the cookie whose value is to be retrieved.
Key (optional) is used to retrieve the value of a subkeyword from the cookie dictionary.
Attribe specifies information about the cookie itself.
You can access the subkeywords of the cookie dictionary by including a key value. If no key is specified when you access the cookie dictionary, all keywords are returned as a single query string.
If the client browser sends two cookies with the same name, the request. Cookie returns a deeper path.

4. servervariables

When browsing a webpage in a browser, the transmission protocol is HTTP. Some client information, such as the customer's IP address, is recorded in the HTTP header file, sometimes the server needs to make different responses based on different client information. In this case, you need to use the servervariables set to obtain the required information.

Request. servervariables (server environment variable)

Common variables:
All HTTP header files sent by the all_http client.
Content_length the length of the content sent by the client.
The data type of the content_type content. For example, "text/html ". It is used together with the query of additional information, such as HTTP query get, post, and put.
Local_addr returns the server address that receives the request. This variable is very important if you look for the address used by the request on a multi-host machine bound with multiple IP addresses.
The logon_user user logs on to the Windows NT account.
QUERY_STRING query the question mark (?) in an HTTP request (?) .
The IP address of the remote host (client) That remote_addr sends the request.
The name of the host (client) That remote_host sends the request. If the server does not have this information, it will set the mote_addr variable to null.
Request_method this method is used to request. It is equivalent to get, Head, post, and so on for HTTP.
SERVER_NAME displays the server host name, DNS alias, or IP address in the Self-referenced URL.
The Port Number of the request sent by server_port.

2. built-in object response

The response object is used to control the information sent to the user, including sending the information directly to the browser, redirecting the browser to another URL, or setting the cookie value.

Response. Collection | property | Method

I. Attributes
1. Buffer
The buffer attribute indicates whether to buffer page output. When the buffer page is output, the server sends the response to the client browser only after all the server scripts on the current page are processed or the flush or end method is called, after the server sends the output to the client browser, the buffer attribute cannot be set. Therefore, response. buffer should be called in the first line of the. asp file.

2. charset
The charset attribute attaches the character set name to the end of the Content-Type title in the response object. For ASP pages that do not contain the response. charset attribute, the Content-Type title is: Content-Type: text/html.

3. contenttype
The contenttype attribute specifies the HTTP content type of the server response. If contenttype is not specified, the default value is text/html.

4. Expires
The expires attribute specifies the time before the page cached on the browser expires. If you return to this page before a page expires, the page in the buffer zone is displayed. If response. expires is set to 0, the cached page can expire immediately. This is a more practical attribute. When you enter the web site through ASP login page, you should use this attribute to immediately expire the login page to ensure security.

5. expiresabsolute
Different from the expires attribute, the expiresabsolute attribute specifies the exact expiration date and time of the page cached in the browser. If you return to this page before expiration, the page in the cache is displayed. If no time is specified, the home page will expire at midnight that day. If no date is specified, the home page will expire at the specified time on the day when the script runs.

Ii. Method

1. Clear
You can use the clear method to clear all HTML output in the buffer. However, the clear method only clears the response body without clearing the response title. You can use this method to handle errors. However, if response. buffer is not set to true, this method will cause a runtime error.

2. End
The end method causes the Web server to stop processing the script and return the current result. The remaining content in the file will not be processed. If response. buffer has been set to true, call response. End to buffer the output.

3. Flush
The flush method immediately sends the output in the buffer. If response. buffer is not set to true, this method will cause a runtime error.

4. Redirect
The redirect method redirects the browser to the URL specified by the program immediately. This is also a method we often use, so that programmers can specify different pages for different customers or different pages according to different situations based on different responses of customers. Once the Redirect method is used, any response body content explicitly set on the page will be ignored. However, this method does not send other HTTP headers set for this page to the client, and generates an automatic response body that uses the redirected URL as the link.

5. Write
The write method is one of the most commonly used methods. It writes the specified string to the current HTTP output.

Iii. Set

The response object has only one set-cookie
Set the cookie value in the cookie set. If the specified cookie does not exist, create it. If yes, a new value is set and the old value is deleted.

Response. Cookies (cookies) [(key) |. Attribute] = Value

Here, the cookie is the name of the specified cookie. If the key is specified, the cookie is a dictionary.
Attribute specifies information about the cookie itself. Attribute can be one of the following:
If the domain is specified, the cookie will be sent to the request for this domain.
Expires specifies the cookie expiration date. This date must be set to store cookies on the client disk after the session ends. If

If the setting of the item property does not exceed the current date, the cookie will expire after the task ends.
Haskeys specifies whether the cookie contains a keyword.
If path is specified, the cookie will only be sent to the request for this path. If this attribute is not set, the Application Path is used.

3. Application object.

I. Attributes

Although the application object does not have built-in attributes, we can use the following syntax to set user-defined attributes, also known as collections.
Application ("attribute/Set Name") = Value

Once an application object is assigned a property, it will persist until the Web Server service is disabled to stop the application. Because the values stored in the Application object can be read by all users of the application, the attributes of the Application object are especially suitable for transmitting information between users of the application.

Ii. Method

The application object has two methods, both of which are used to process data written by multiple users in the application.

1. Lock Method

Prohibit other customers from modifying the properties of the Application object.
The lock method prevents other customers from modifying the variables stored in the Application object to ensure that only one customer can modify and access the variables at the same time.

Application variable. If you do not explicitly call the unlock method, the server will unlock the application object after the. asp file ends or times out.

2. Unlock Method

Opposite to the lock method, the unlock method allows other users to modify the attributes of the Application object.

Iii. Events

1. application_onstart
The application_onstart event occurs before the first session (session_onstart event) is created. The application_onstart event is triggered when the web server starts and allows requests to files contained in the application. The application_onstart event processing process must be written in the global. Asa file.

2. application_onend
The application_onend event occurs after the session_onend event when the application exits. The process of processing the application_onend event must also be written in the global. Asa file.

4. Session object.

We can use the session object to store the information required for a specific user session. When a user jumps between pages of an application, the variables stored in the session object are not cleared, and the variables always exist when the user accesses the page in the application. When a user requests a web page from an application, if the user does not have a session, the web server automatically creates a session object. When a session expires or is abandoned, the server terminates the session. You can manage session objects on the server by sending a unique cookie to the client program. When a user requests a page in an ASP application for the first time, ASP checks the HTTP header information to check whether a cookie named aspsessionid is sent in the message. If yes, the server starts a new session and generates a globally unique value for the session. This cookie is used when the value is sent to the client as the value of the new aspsessionid cookie, you can access the information of the customer program stored on the server. Session objects are most commonly used to store user preferences. For example, if you specify that you do not like to view images, you can store the information in the session object. In addition, it is often used in the process of identifying customer identities. Note that the session status is retained only in the browser that supports cookies. If the cookie option is disabled, the session cannot be used.

I. Attributes
1. sessionid

The sessionid attribute returns the user's session ID. When creating a session, the server generates a separate identifier for each session. The session ID is returned as a long integer. In many cases, sessionid can be used for web page registration statistics.

2. Timeout
The timeout attribute specifies the timeout period for the session object of the application in minutes. If the user does not refresh or request the webpage within the timeout period, the session will be terminated.

Ii. Method

The Session object has only one method, namely, abandon. The abandon method deletes all objects stored in the session object and releases the source of these objects. If you do not explicitly call the abandon method, the server will delete these objects once the session times out.

Iii. Events

The Session object has two events that can be used to start and release a session object.

1. The session_onstart event occurs when the server creates a new session. The server processes the script before executing the request page.

Session_onstart events are the best time to set session-period variables, because they are set before accessing any page.

2. The session_onend event occurs when the session is abandoned or timed out.

V. Server objects

The server object provides access to methods and attributes on the server. Most of the methods and attributes serve as the functional services of the utility. With the server object, you can start ActiveX Object routines on the server and use the Active Server Service to provide functions such as HTML and URL encoding.

I. Syntax

Server. Property | Method

Ii. Attributes

The time-out value of scripttimeout, Which is timeout after the script runs beyond this time. The following code specifies that the server processing script is

Timeout 100 seconds later.

Iii. Methods

1. htmlencode Method

The htmlencode method allows you to encode a specific string in HTML. Although HTML can display most of the text you write into an ASP file, when you need to actually contain the characters used in the HTML tag, you will encounter problems. This is because when the browser reads such a string, it tries to explain it.

2. urlencode Method

Just as the htmlencode method enables the customer to translate strings into acceptable HTML formats, the urlencode of the Server Object

The method can correctly encode strings according to URL rules. When string data is transmitted to the server in the form of URL

Spaces or special characters are not allowed. To do this, if you want to perform URL encoding before sending a string, you can use

Server. urlencode method.

3. mappath Method

The mappath method maps the specified relative or virtual path to the corresponding physical directory on the server.
Syntax: Server. mappath (PATH)
Path specifies the relative or virtual path to map to the physical directory. 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 that the mappath method does not check whether the returned path is correct or whether it exists on the server.

4. Createobject Method

Server. Createobject is probably the most practical and powerful feature in ASP. It is used to create ActiveX component instances registered on the server. This is a very important feature, because the use of ActiveX Components allows you to easily expand ActiveX capabilities, it is the use of ActiveX components, You can implement the vital functions, for example, database connections, file access, AD display, and other vbscripts cannot provide or simply rely on the functions that ActiveX alone can do. It is precisely because of these components that ASP has a powerful vitality.
The syntax is as follows:
Server. Createobject ("component name ")
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.

 

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.