Operation of HTTP header method in ASP

Source: Internet
Author: User
Tags header

We have seen in several places how ASPs Create or modify the HTTP headers that are sent to the customer in response to a page request. There are several properties and methods in the response object that can help us do a little. Here are some header methods:

· Controls caching and expiration.

· Creates a state and a custom HTTP header.

· Specifies the MIME type or content type.

· Add a Pics label.

The next step is to study each aspect briefly. On the Response Object home page (show_response.asp), click the related property name or method name to check the properties and methods that we are talking about.

1. Cache and "Expiration" ASP Web pages

Users ' browsers, as well as their any proxy servers with servers, can cache HTML and Web pages created with ASP. When the user subsequently requests the page, the browser sends a "last modified" request to the server (using a http_if_modified_since header that contains the date of the cached version) to ask if the page has been modified.

If it is not modified, the server applies the status code and the message "304 not Modified" to respond, the browser will use the cached content instead of downloading a copy over the network. If a modified version already exists, it is sent with the "OK" status code and the message.

1) Response.cachecontol Property

Other factors can also affect the process. However, any proxy server within the network route used by the Web page (typically located on the client side) can be discarded by setting the Response.CacheControl property as private to discard the cached Web page. This is the default for ASP Web pages in ASP 3.0 and is not set. This is especially useful when web pages are specially tailored for individual visitors. This can prevent other users on the same network from entering the same Web page. Allows the server to cache Web pages when the CacheControl property value is set to public. Note that some proxy servers may behave differently, or ignore or bypass the header.

In IE4, it is possible to get a false "this page has expired" message when the proxy server cache is available. We have provided a Web page (expiretest_form.asp) that can be tested on the network through its own proxy server to check the impact of this property. You can click Response in the Response Object home page. CacheControl "link to display this page. As shown in the following illustration:

When this page is submitted to the Expiretest_result.asp Web page, you can set the Response.CacheControl property, and then insert the value in the Web page and the time the script was executed:

<%
If Request.Form(“public”) = “on” Then ‘Cache-Control check box was ticked
 Response.CacheControl = “Public”
Else
 Response.CacheControl = “Private”
End If
%>
<HTML>
...
Cache-Control is: <B><% = Response.CacheControl %></B><P>
Value in text box is: <B><% Response.Write Request.Form(“textbox”) %>
<%
Response.Write Right(“0” & Hour(Now),2) & “:” & Right(“0” & Minute(Now),_
& 2) & “:” & Right(“0” & Second(Now),2)
%></B>

You can see whether the code executes automatically or uses a cached copy by clicking Back and Forward on the browser.

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.