please dont rip this site

Cookies

The Cookies collection sets the value of a cookie. If the specified cookie does not exist, it is created. If it exists, it takes the new value and the old value is discarded.

http://techref.massmind.org/techref/showall.asp

Syntax

Response.Cookies(cookie)[(key)|.attribute] = value

Parameters

cookie

The name of the cookie.

key

An optional parameter. If key is specified, cookie is a dictionary, and key is set to value.

attribute

Specifies information about the cookie itself. The attribute parameter can be one of the following.

Name

Description

Expires

Write-only. The date on which the cookie expires.

Domain

Write-only. If specified, the cookie is sent only to requests to this domain.

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.

Secure

Write-only. Specifies whether the cookie is secure.

HasKeys

Read-only. Specifies whether the cookie contains keys.

Value

Specifies the value to assign to key or attribute.

Remarks

If a cookie with a key is created, for example:

<% 
Response.Cookies("mycookie")("type1") = "sugar"
Response.Cookies("mycookie")("type2") = "ginger snap"
%>

The following header is sent:

Set-Cookie:MYCOOKIE=TYPE1=sugar&TYPE2=ginger+snap
 

A subsequent assignment to myCookie without specifying a key, would destroy type1 and type2. This is shown in the following example.

<% Response.Cookies("myCookie") = "chocolate chip" %> 
 

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".

Conversely, calling a cookie with a key destroys any nonkey values it might have contained. For example, if after the preceding code, you call Response.Cookies with the following:

<% Response.Cookies("myCookie")("newType") = "peanut butter" %> 
 

The value chocolate chip is discarded and newType would be set to peanut butter.

To determine whether a cookie has keys, use the following syntax:

<%= Response.Cookies("myCookie").HasKeys %> 
 

If myCookie is a cookie dictionary, the preceding value evaluates to TRUE. Otherwise, it evaluates to FALSE.

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:

<% 
For Each cookie in Response.Cookies
Response.Cookie(cookie).ExpiresAbsolute = #July 4, 1997#
Next
%>

You can also use an iterator to set the values of all the cookies in a collection, or all the keys in a cookie. However, the iterator, when invoked on a cookie that does not have keys, does not execute. To avoid this you can first use the .HasKeys syntax to check to see whether a cookie has any keys. This is demonstrated in the following example:

<% 
If Not cookie.HasKeys Then
'Set the value of the cookie Response.Cookies(cookie) = "" Else 'Set the value for each key in the the cookie collection For Each key in Response.Cookies(cookie) Response.Cookies(cookie)(key) = "" Next key %>

Examples

The following examples demonstrate how you can set a value for a cookie and assign values to its attributes.

<% 
Response.Cookies("Type") = "Chocolate Chip"
Response.Cookies("Type").Expires = "July 31, 1997"
Response.Cookies("Type").Domain = "msn.com"
Response.Cookies("Type").Path = "/www/home/"
Response.Cookies("Type").Secure = FALSE
%>

Applies To

Response Object

See Also

Request.Cookies


© Microsoft Corporation. All rights reserved.


file: /Techref/language/asp/OBJ/introbj_14.htm, 7KB, , updated: 2004/3/2 22:43, local time: 2024/3/29 07:14,
TOP NEW HELP FIND: 
3.238.12.0:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://www.massmind.org/techref/language/asp/OBJ/introbj_14.htm"> Cookies</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to www.massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .