Sideway BICK BlogSideway BICK BLOG from Sideway

A Sideway to Sideway Home

Link:http://output.to/sideway/default.asp?qno=120200002

Expires / ExpiresAbsolute

Response Object

Another important function of Response object is the output of HTTP headers to the client. As part of the HTTP header, these types of response objects should be sent before sending any body content to the client.

Response.Expires Property

Response.Expires property sets the length of the time in minutes that the HTML page can be cached on the browser to calculate the absolute expires date & time according to the date & time on the server for the HTTP Expires header.

Syntax:

Response.Expires [=number]

 Or in an ASP file. Imply

<% Response.Expires = number  %>

Parameters:

number

The parameter "number" is the value of duration time in minute of a page in a cache. The data type of "number" is numbers. A value of negative number means immediate expiration. When the calculated absolute expires date from the supplied value of number exceeds January 18, 2038, IIS server will returns an error.

Remarks:

If the same page is requested by client before the page expires, the cached version will be displayed by the client.

If there are multiple Response.Expires or Response.ExpiresAbsolute  on the same page, the web server will use the shortest time period.

Since the system time on the client may not be the same as the system time on the server, setting the parameter of expires to zero sometime does not have the effect of expiring the response immediately. Therefore setting the parameter of expires to a negavtive number can ensure the expiring of the response immediately.

Examples:

  • Default value with No Response.Expires

    ASP script command:

    <%  %>

    HTTP header response:

    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.1
    Date: Tue, 31 Jan 2012 15:19:08 GMT
    X-Powered-By: ASP.NET
    Content-Length: 0
    Content-Type: text/html
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

  • Response.Expires with value 10

    ASP script command:

    <% Response.Expires = 10 %>

    HTTP header response: 

    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.1
    Date: Tue, 31 Jan 2012 15:19:08 GMT
    X-Powered-By: ASP.NET
    Content-Length: 0
    Expires: Tue, 31 Jan 2012 15:29:08 GMT:29:08 GMT
    Content-Type: text/html
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

  • Response.Expires with value 0

    ASP script command:

    <% Response.Expires = 0 %>

    HTTP header response: 

    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.1
    Date: Tue, 31 Jan 2012 15:19:08 GMT
    X-Powered-By: ASP.NET
    Content-Length: 0
    Expires: Tue, 31 Jan 2012 15:19:08 GMT:19:08 GMT
    Content-Type: text/html
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

  • Response.Expires with value -1

    ASP script command:

    <% Response.Expires = -1 %>

    HTTP header response: 

    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.1
    Date: Tue, 31 Jan 2012 15:19:08 GMT
    X-Powered-By: ASP.NET
    Content-Length: 0
    Expires: Tue, 31 Jan 2012 15:18:08 GMT:18:08 GMT
    Content-Type: text/html
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

  • Multiple Response.Expires with value 10 and 20

    ASP script command:

    <% Response.Charset = 10 %>
    <% Response.Charset = 20 %> 

    HTTP header response: 

    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.1
    Date: Tue, 31 Jan 2012 15:19:08 GMT
    X-Powered-By: ASP.NET
    Content-Length: 0
    Expires: Tue, 31 Jan 2012 15:29:08 GMT:29:08 GMT
    Content-Type: text/html
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

Response.ExpiresAbsolute Property

Response.ExpiresAbsolute property sets the actual  expire date and time that the HTML page can be cached on the browser for the HTTP Expires header.

Syntax:

Response.ExpiresAbsolute [=[date][time]]

 Or in an ASP file. Imply

<% Response.Expires = [date][time]  %>

Parameters:

date

The parameter "date" is the value of expire date of a page in a cache. The data type of "date" is window date format. In general, Date values must be enclosed within pound signs (#) and be in the format M/d/yyyy. But the value sent in the HTTP Expires header will convert to the RFC-1123 date format. If the value of date is not set, the default value of date is the day of the ASP file run. When the absolute expires date from the supplied value of number exceeds January 18, 2038, IIS server will returns an error.

time

The parameter "time" is the value of expire time of a page in a cache. The data type of "time" is window time format. In general, time values must be enclosed within pound signs (#) and be in the format hh:mm:ss. But the value sent in the HTTP Expires header will convert to the RFC-1123 date format with GMT time zone. If the value of time is not set, the default value of time is the midnight of the day of the ASP file run in GMT format.

Remarks: Remarks:

The value of the parameters must be enclosed in pound marks (# #)

If the same page is requested by client before the page expires, the cached version will be displayed by the client.

If there are multiple Response.ExpiresAbsolute or Response.Expires in the same page, the web server will use the shortest time period.

Examples:

  • Default value with No Response.ExpiresAbsolute

    ASP script command:t command:

    <%  %>

    HTTP header response:

    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.1
    Date: Tue, 31 Jan 2012 15:19:08 GMT
    X-Powered-By: ASP.NET
    Content-Length: 0
    Content-Type: text/html
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

  • Response.ExpiresAbsolute with value "February 18, 2012 13:30:15"

    ASP script command:

    <% Response.ExpiresAbsolute = #February 18, 2012 13:30:15# %>

    HTTP header response: 

    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.1
    Date: Tue, 31 Jan 2012 15:19:08 GMT
    X-Powered-By: ASP.NET
    Content-Length: 0
    Expires: Sat, 18 Feb 2012 05:30:14 GMT
    Content-Type: text/html
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

  • Response.ExpiresAbsolute with value "February 18, 2012"

    ASP script command

    <% Response.ExpiresAbsolute = #February 18, 2012# %>

    HTTP header response: 

    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.1
    Date: Tue, 31 Jan 2012 15:19:08 GMT
    X-Powered-By: ASP.NET
    Content-Length: 0
    Expires: Fri, 17 Feb 2012 16:00:00 GMT
    Content-Type: text/html
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

  • Response.ExpiresAbsolute with value "February 18, 2012 13:30:15"

    ASP script command:

    <% Response.ExpiresAbsolute = #13:30:15# %>

    HTTP header response: 

    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.1
    Date: Tue, 31 Jan 2012 15:19:08 GMT
    X-Powered-By: ASP.NET
    Content-Length: 0
    Expires: Tue, 31 Jan 2012 05:30:14 GMT
    Content-Type: text/html
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

  • Multiple Response.ExpiresAbsolute with value "February 18, 2012 13:30:15" and Response.Expires with value 10

    ASP script command:

    <% Response.Charset = 10 %>
    <% Response.ExpiresAbsolute = #February 18, 2012 13:30:15# %>  

    HTTP header response: 

    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.1
    Date: Tue, 31 Jan 2012 15:19:08 GMT
    X-Powered-By: ASP.NET
    Content-Length: 0
    Expires: Tue, 31 Jan 2012 15:29:08 GMT
    Content-Type: text/html text/html
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

Link:http://output.to/sideway/default.asp?qno=120200001

ContentType / Charset

Response Object

Another important function of Response object is the output of HTTP headers to the client. As part of the HTTP header, these types of response objects should be sent before sending any body content to the client.

Response.ContentType Property

Response.ContentType sets the value of content-type header to specify the content type of the HTTP response .

Syntax:

Response.ContentType [=Content Type]

 Or in an ASP file. Imply

<% Response.Charset = Content Type %>

Parameters:

Content Type

The parameter "Content Type" is the value of the content-type header. The data type of "Content Type" is strings of format "type/subtype" and the value must be enclosed in quotation marks (" "). "type" is the general content category and "subtype" is the specific content type. The possible values of "Content Type" are

Type Type/Subtype
text : textual information text/plain : textual data
text/html : HTML
text/css : Cascading Style Sheets
text/xml : Extensible Markup Language
image : image data image/gif : GIF image
image/jpeg : JPEG image
image/png : Portable Network Graphics
image/tiff : Tag Image File Format
image/svg+xml : SVG vector image
audio : audio data audio/mp4 : MP4 audio
audio/mpeg : MP3 audio
audio/ogg : Ogg
video : video data video/mpeg : MPEG-1
video/mp4 : MP4
video/quicktime : QuickTime video
video/ogg : Ogg video
application : processed data application/pdf : Portable Document Format
application/xhtml+xml : XHTML

Remarks:

In general, the default value of the Content Type parameter is "text/html" if there is  Content Type property is not set for the page.

Since each page can only be assigned to one Content Type, the last instance of Response.ContentType in the HTTP header setting of a ASP file will replace all previous Response.ContentType Setting.

If the response buffering is not enbled, the ContentType header setting must be set before any response is sent to the client.

Examples:

  • Default value with No Response.ContentType propertye property

    ASP script command:

    <%  %>

    HTTP header response:

    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.1
    Date: Tue, 31 Jan 2012 15:19:08 GMT
    X-Powered-By: ASP.NET
    Content-Length: 0
    Content-Type: text/html
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

  • Response.ContentType with value "image/jpeg"

    ASP script command:

    <% Response.Charset = "image/jpeg" %>

    HTTP header response: 

    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.1
    Date: Tue, 31 Jan 2012 15:19:08 GMT
    X-Powered-By: ASP.NET
    Content-Length: 0
    Content-Type: image/jpeg
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

  • Multi Response.Charset with value "image/jpeg" and "text/html"

    ASP script command:

    <% Response.Charset = "image/jpeg" %>
    <% Response.ContentType = "text/html" %> 

    HTTP header response: response: 

    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.1
    Date: Tue, 31 Jan 2012 15:19:08 GMT
    X-Powered-By: ASP.NET
    Content-Length: 0
    Content-Type: text/html
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/PPP; path=/
    Cache-control: private

Response.Charset Property

Response.Charset property appends the name of character set to the charset parameter in the content-type header to specify the character encoding of the response contents for the browser.

Syntax:

Response.Charset (CharsetName)

 Or in an ASP file. Imply

<% Response.Charset = CharsetName  %>

Parameters:

CharsetName

The parameter "CharsetName" is the value of the Character set name appended to the charset parameter of the content-type header. The data type of "CharsetName" is strings and the value must be enclosed in quotation marks (" "). The possible values of "CharsetName" are

ValueDescription
US-ASCIIANSI_X3.4-1968
ISO-8859-1ISO_8859-1:1987
ISO-8859-2ISO_8859-2:1987
ISO-8859-3ISO_8859-3:1988
ISO-8859-4ISO_8859-4:1988
ISO-8859-5ISO_8859-5:1988
ISO-8859-6ISO_8859-6:1987
ISO-8859-7ISO_8859-7:1987
ISO-8859-8ISO_8859-8:1988
ISO-8859-9ISO_8859-9:1989
ISO-8859-10ISO_8859-10:1992
Shift_JISShift_JIS
EUC-JP Extended_UNIX_Code_Packed_Format_for_Japanese
ISO-2022-KRISO-2022-KR
EUC-KREUC-KR
ISO-2022-JPISO-2022-JP
ISO-2022-JP-2ISO-2022-JP-2
ISO-8859-6-EISO-8859-6-E
ISO-8859-6-IISO-8859-6-I
ISO-8859-8-EISO-8859-8-E
ISO-8859-8-IISO-8859-8-I
UTF-8UTF-8
ISO-8859-13ISO-8859-13
ISO-8859-14ISO_8859-14:1998
ISO-8859-15ISO-8859-15
ISO-8859-16ISO_8859-16:2001
GBKGBK
GB18030GB18030
GB2312GB2312
Big5Big5
KOI8-RKOI8-R
windows-1252windows-1252

Remarks:

Response.Charset property only appends the specified value to the charset parameter of the content-type header. There is no mechanism to validate whether the specified value represents a valid character set. And there is no browser can understand all character set.

Since each page can only be encoded in one charset, the last instance of Response.Charset in the HTTP header setting of a ASP file will replace all previous Response.charset Setting.

If the response buffering is not enbled, the Charset header setting must be set before any response is sent to the client.

The Unicode encoding, UTF-8 is one of the widely used charset to represent Unicode text in page with mixed languages

Besides, the value of CharsetName and value of codepage should match with each other. Since the code page is the value to specify the encoding code page used by the web server to general the response contents, while the character set is the value to specify the decoding character set used by the page browser. Therefore, a codepage setting, by Response.CodePage, Session.CodePage, @CodePage, or AspCodePage, is needed to ensure the readability of the displayed text. And a charsetname setting should also be used to ensure the decoding character set used in client browser match with the encoding code page used in the web server.web server.

Name of Character set can refer to http://www.iana.org/assignments/character-sets

Examples:

  • Default value with No Response.Charset property

    ASP script command:

    <%  %>

    HTTP header response:

    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.1
    Date: Tue, 31 Jan 2012 15:19:08 GMT
    X-Powered-By: ASP.NET
    Content-Length: 0
    Content-Type: text/html
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

  • Response.Charset with value "UTF-8"

    ASP script command:

    <% Response.Charset = "UTF-8" %>

    HTTP header response: 

    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.1
    Date: Tue, 31 Jan 2012 15:19:08 GMT
    X-Powered-By: ASP.NET
    Content-Length: 0
    Content-Type: text/html; Charset=UTF-8
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

  • Multiple Response.Charset with value "UTF-8" and "Big5"

    ASP script command:pt command:

    <% Response.Charset = "UTF-8" %>
    <% Response.Charset = "Big5" %> 

    HTTP header response: 

    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.1
    Date: Tue, 31 Jan 2012 15:19:08 GMT
    X-Powered-By: ASP.NET
    Content-Length: 0
    Content-Type: text/html; Charset=Big5
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

Previous Month  FEB  2012  Next Month
SMTWTFS
1234
567891011
12131415161718
19202122232425
26272829

Previous Month  MAY  2013  Next Month
SMTWTFS
1234
567891011
12131415161718
19202122232425
262728293031

Sideway BICK Blog

01/02


Copyright © 2000-2020 Sideway . All rights reserved Disclaimerslast modified on 26 January 2013