Introduction to http meta data

Source: Internet
Author: User
Tags reading gif microsoft iis

<Head>
<Meta http-equiv = "Content-Type" content = "text/html;">
</Head>
1 Content-Type
Content-Type is a very important Content in the returned message. It identifies the Type of the returned Content, and its value is in the format of "primary Type/subtype, for example, the most common one is text/html, which means that the returned content is of the text type, and the text is in HTML format. In principle, the browser determines how to display the returned message body Content based on Content-Type. Common content types include:
Text/html HTML text
Image/jpeg jpg image
Image/gif image
Application/xml XML document
Audio/x-mpegurl MP3 file list. If Winamp is installed, you can directly open it in an M3U File.
For more Content types, see "HKCR \ MIME \ Database \ Content Type" in the registry.
For IE 6 browser, if the Type in Content-Type is different from the actual message body Type, it will analyze the actual Type based on the Type in the Content, common image formats such as JPG and GIF can be correctly identified, regardless of what is written in Content-Type.
If Content-Type specifies a Type that can be directly opened by the browser, the browser will directly open its Content and display it. If it is associated with other application types, in this case, you need to check the registration information of this type in the registry. If you allow direct opening without asking, the associated application will be called up directly to open the file, however, if it cannot be opened directly, you will be asked if it is enabled. For a type that is not associated with any application, ie does not know how to open it. In this case, IE6 will treat it as XML and try to open it.
2 Content-Disposition
If the AddHeader method is used to add the Content-Disposition segment to the HTTP message header and specify its value as "attachment", no matter what type of file the file is, the browser will prompt us to download this file, because it considers the message body behind it as an "attachment" and does not need to be processed by the browser. For example, write the following statement in ASP. Net:
Response. AddHeader ("Content-Disposition: attachment ");
The result of the request is as follows:
HTTP/1.1 200 OK
Server: Microsoft-Microsoft IIS/5.1
Date: Thu, 23 Mar 2006 07:54:53 GMT
Content-Disposition: attachment
Cache-Control: private
Content-Type: text/html; charset = UTF-8
......
That is to say, the AddHeader function can be used to add custom content to the HTTP message header. This method forces the browser to prompt the download of the file, even if the file is a known class type, based on HTML web pages. If you want to display a default file name when downloading, you only need to add "filename = file name" after the previous sentence. For example:
Response. AddHeader ("Content-Disposition: attachment; filename=mypage.htm ");
3 Content-Type and Content-Disposition
What if we use Content-Type and Content-Disposition together?
When you open a webpage, the browser will first check whether the Content-Disposition: attachment item exists. If yes, the browser will prompt you to download the file regardless of the Content-Type value.
If filename is specified, the default file name is displayed. Note that in IE6, in addition to the "save" button, there is a "open" button. The file type is determined by the file extension name specified in filename. for example, if filenamepolicmypic.jpg is used, the browser will find the default image viewer to open the file.
If filename is not specified, the browser determines the file Type based on the Type in Content-Type. For example, if the Content-Type is image/gif, then, you will find the default tool for reading GIF images, and set the file name to the main name of the requested webpage (without the extension) plus the file extension corresponding to this file, for example, the requested mypage.aspxwill automatically become mypage.gif. If the Content-Type value is not specified, it is "text/html" by default, and the stored file name is the requested webpage file name.
However, if Content-Disposition is not specified, the situation is the same as discussed in Content-Type.

4 Cache
The Cache in the returned message is used to specify the webpage Cache. We can often see that the speed of opening a webpage is not fast, but it will be much faster when you open it again, because the browser has already cached this page, when this page is opened again in the same browser window, it will not be retrieved from the server again. The Cache of web pages is controlled by "cache-control" in the HTTP message header. common values include private, no-Cache, max-age, and must-revalidate, the default value is private. Its functions can be divided into the following situations based on different review methods:
(1) open a new window
If the cache-control values are private, no-cache, and must-revalidate, the server will be accessed again when a new window is opened. If the max-age value is specified, the server will not be accessed again within the time range. For example:
Cache-control: max-age = 5
Indicates that the webpage will not go to the server again within 5 seconds after it is accessed.
(2) Press enter in the address bar.
If the value is private or must-revalidate (not the same as on the Internet), the server will be accessed only when the first access is made and will not be accessed later. If the value is no-cache, it will be accessed every time. If the value is max-age, the access will not be repeated before expiration.
(3) Back and press the button
If the values are private, must-revalidate, and max-age, no re-access will be performed. If the value is no-cache, the access will be repeated each time.
(4) press the refresh button
No matter what the value is, it will be accessed again

When the Cache-control value is "no-cache", accessing this page will not leave page backup in the temporary article folder on the Internet.
In addition, specifying the "Expires" value also affects the cache. For example, if you specify the Expires value as a time that has passed, if you repeatedly press enter in the address bar when accessing this network, the access will be repeated each time:
Expires: Fri, 31 Dec 1999 16:00:00 GMT

In ASP, the Expires and ExpiresAbsolute attributes of the Response object can be used to control the Expires value. The CacheControl attribute of the Response object can be used to control the Cache-control value. For example:
Response. ExpiresAbsolute = #2000-1-1 # 'specifies the absolute expiration time, which is the local time of the server and is automatically converted to GMT.
Response. Expires = 20' specifies the relative expiration time, in minutes, which indicates how many minutes have expired since the current time.
Response. CacheControl = "no-cache"

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.