在ASP中設cookie,不知此COOKIE有沒有時間極限?

來源:互聯網
上載者:User
cookie Cookies<br>
The Cookies collection sets the value of a cookie. If the specified cookie does not exist, it is created. If the cookie exists, it takes the new value and the old value is discarded.<br>
<br>
Syntax<br>
Response.Cookies(cookie)[(key)|.attribute] = value <br>
<br>
<br>
<br>
Parameters<br>
cookie <br>
The name of the cookie.<br>
<br>
key <br>
An optional parameter. If key is specified, cookie is a dictionary, and key is set to value.<br>
<br>
attribute <br>
Specifies information about the cookie itself. The attribute parameter can be one of the following. Name Description <br>
Domain Write-only. If specified, the cookie is sent only to requests to this domain. <br>
Expires Write-only. The date on which the cookie expires. This date must be set in order for the cookie to be stored on the client's disk after the session ends. If this attribute is not set to a date beyond the current date, the cookie will expire when the session ends. <br>
HasKeys Read-only. Specifies whether the cookie contains keys. <br>
Path  Write-only. If specified, the cookie is sent only to requests to this path. If this attribute is not set, the application path is used. <br>
Secure Write-only. Specifies whether the cookie is secure. <br>
<br>
<br>
<br>
Value <br>
Specifies the value to assign to key or attribute. <br>
Remarks<br>
If a cookie with a key is created, as in the following script,<br>
<br>
<% <br>
  Response.Cookies("mycookie")("type1") = "sugar"<br>
  Response.Cookies("mycookie")("type2") = "ginger snap"<br>
%> <br>
<br>
this header is sent:<br>
<br>
Set-Cookie:MYCOOKIE=TYPE1=sugar&TYPE2=ginger+snap<br>
<br>
A subsequent assignment to myCookie without specifying a key, would destroy type1 and type2. This is shown in the following example.<br>
<br>
<% Response.Cookies("myCookie") = "chocolate chip" %> <br>
<br>
In the preceding example, the keys type1 and type2 are destroyed and their values are discarded. The myCookie cookie now has the value chocolate chip. <br>
<br>
Conversely, if you call a cookie with a key, it destroys any non-key values the cookie contained. For example, if after the preceding code you call Response.Cookies with the following<br>
<br>
<% Response.Cookies("myCookie")("newType") = "peanut butter" %> <br>
<br>
The value chocolate chip is discarded and newType would be set to peanut butter.<br>
<br>
To determine whether a cookie has keys, use the following syntax.<br>
<br>
<%= Response.Cookies("myCookie").HasKeys %> <br>
<br>
If myCookie is a cookie dictionary, the preceding value is TRUE. Otherwise, it is FALSE.<br>
<br>
You can use an iterator to set cookie attributes. For example, to set all of the cookies to expire on a particular date, use the following syntax.<br>
<br>
<% <br>
  For Each cookie in Response.Cookies<br>
    Response.Cookie(cookie).ExpiresAbsolute = #July 4, 1997#<br>
  Next<br>
%> <br>
<br>
You can also iterate through the values of all the cookies in a collection, or all the keys in a cookie. However, if you try to iterate through the values for a cookie that does not have keys, nothing will be returned. To avoid this, you can first use the .HasKeys syntax to check whether a cookie has any keys. This is demonstrated in the following example.<br>
<br>
<% <br>
  If Not cookie.HasKeys Then<br>
    'Set the value of the cookie. <br>
    Response.Cookies(cookie) = ""<br>
  Else<br>
    'Set the value for each key in the cookie collection.<br>
&am



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.