Uncovering the Mystery of ASP (3)

Source: Internet
Author: User
Tags date character set contains flush header html page variable domain
Response objects

Author: Sage of the Rice Fairy

Response in contrast to request (request is to obtain client HTTP information), the Response object is used to control the information that is sent to the user, including sending information directly to the browser, redirecting the browser to another URL, or setting the value of the cookie.

Grammar
Response.collection|property|method

One, property
1, Buffer Properties
The Buffer property indicates whether the page output is buffered. When the page output is buffered, the server sends the response to the client browser only after all server scripts for the current page have been processed or the Flush or End method is invoked, and the server will no longer be able to set the buffer property after it has been sent to the client browser. You should therefore call Response.Buffer on the first line of the. asp file.
2, CharSet property
The Charset property attaches the character set name to the back of the Content-type header in the Response object. For ASP pages that do not contain the Response.Charset property, the Content-type title will be: content-type:text/html.
We can specify Content-type headers in the. asp file, such as:
<% response.charset= "gb2312")%>
The following results are produced:
content-type:text/html; charset=gb2312
Note that the feature inserts it into the Content-type header, regardless of whether the character set represented by the string is valid. And if a page contains more than one tag that contains Response.Charset, each Response.Charset replaces the previous charsetname. In this way, the character set is set to the value specified by the last instance of Response.Charset in the page.

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

4, Expires Property
The Expires property specifies how much time is available to cache the paged memory on the browser. If a user returns to this page before a page expires, the page in the buffer is displayed. If you set response.expires=0, you can make cached pages expire immediately. This is a more practical property, when the customer through the ASP's Landing page into the Web site, you should use this property to make the landing page expire immediately to ensure security.

5, ExpiresAbsolute Property
Unlike the Expires property, the ExpiresAbsolute property specifies the exact expiration date and time of the page that is cached in the browser. The page in the cache is displayed if the user returns to the page before it expires. If no time is specified, the home page expires at midnight on the same day. If no date is specified, the home page expires at a specified time on the day the script is run. The following example specifies that the page expires in 30 seconds on December 10, 1998 9:00. <% response.expiresabsolute= #Dec 12,1998 9:00:30#%>

6, IsClientConnected Property
The IsClientConnected property tells you if the visitor is still connected to your site. Its return value is a Boolean property, and if the return value is true, the reader is still connected to your site. If the return value is False, it indicates that its visitor has left your page.

7, PICS Property
The PICS property allows you to add a Pics-label to the corresponding cursor.
Grammar:
Response.pics=value
This variable represents the textual content of the pics tag you want to add, and in general, we can use the pics tag to rank the content of the Web site, and some browsers or other tools find the tab to decide whether or not to display a page.

8, Satutus Property
The Satutus property, which allows you to set the returned status header, in some cases, such as if you want to dynamically create a condition that might not be true, this attribute is significantly important. Setting this state property can also help you debug your code to see what happens in a particular state.

Second, the method

1. Clear
You can clear all of the HTML output in the buffer with the clean method. However, the clear method clears only the response body and does not clear the response header. You can use this method to handle error conditions. However, if Response.Buffer is not set to TRUE, this method will cause a run-time 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 the Response.Buffer is set to TRUE, the call to Response.End will buffer the output.

3, Flush
The Flush method immediately sends the output in the buffer. If Response.Buffer is not set to TRUE, the method causes a run-time error.

4, Redirect
The Redirect method causes the browser to immediately redirect to the URL specified by the program. This is also a method that we often use so that programmers can specify different pages for different customers depending on the customer's response, or different pages for different situations. Once the Redirect method is used, any response body content that is explicitly set in the page is ignored. However, this method does not send the client a different HTTP header for the page set, resulting in an automatic response body containing the redirected URL as a link. The Redirect method sends the following explicit caption, where the URL is the value passed to the method. such as: <% Response.Redirect ("www.Jusun.com.cn")%>

5, Write
The Write method is one of the most common methods we usually use to write the specified string to the current HTTP output.

6, AddHeader method
You can use the AddHeader method to add a custom header to the output HTML page in the form of the following:
Response.AddHeader Nameofheader, Valueofheader
Valueofheader represents the header name you want to use, Valueofheader specifies the number of headers you want to send, because this method writes the HTTP header, it must be invoked before all the output of the HTML. Response.AddHeader = "CIW", "INFOCD", this line of code creates a header item named the CIW value of INFOCD.

7, AppendToLog method
The handy AppendToLog method allows you to add a text to a specific request in the Web server's log. The text can contain up to 80 characters and cannot contain commas. For example: Response.addtolog textadd, the variable Textadd contains the textual content you want to add to the log, and if you want to use this feature, you must include a log of the Web site that has the page open. You can use MMC to select Web Site, and then right-click on it to select Properties. Select the Web Site tab. , then you must select the Enable Logging check box.

8, BinaryWrite method
The BinaryWrite method allows you to send text-less raw binary information to the browser, which is in the following format: Response.BinaryWrite datetowrite, where datetowrite variables contain the binary information you want to send to the browser. This method is generally used to transmit sounds, images, executables, compressed files, and so on.

Third, the collection
The Response object has only one collection--cookie
Cookies collection sets the value of the cookie. If the specified cookie does not exist, it is created. If it exists, the new value is set and the old value is deleted.
Grammar
Response.Cookies (cookie) [(key) |. Attribute]=value
The cookie here is the name of the specified cookie. If a key is specified, the cookie is a dictionary. attribute specifies information about the cookie itself. Attribute parameters can be one of the following:
If domain is specified, the cookie is sent to the request in the domain.
EXPIRES Specifies the expiration date for the cookie. To store cookies on the client disk after the session has ended, you must set the date. If the setting for this property does not exceed the current date, the cookie expires after the task ends.
HasKeys Specifies whether the cookie contains keywords.
If path is specified, the cookie is sent only to the request for that path. If this property is not set, the path to the application is used.



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.