How to set and retrieve cookie values?
Expires property expects to receive a specific data when to expire. For example,
the following code will set our user Information cookie to expire on August 1,
= #August 1, 2000#
VBScript, you see specify a literal date by surrounding it with pound sign (#).
There are also many other ways that you could specify the expiration date.
following list illustrates other methods of setting the Expires property to a
#January 27. 2001#
· C date (1/27/2001)
Date Serial (2001,1,27)
the methods listed are valid ways to set the Expires property. However, what if
you want the cookie to expire a fixed number of days or weeks from the current
date? To do this, use the Date function. The data function allows you to add a
number to it to increment or decrement the date value returned. For example, if
you want to obtain a data five days in the future, Data + 5 would do the trick.
Data - 5 would return a date five days in the past.
syntax is helpful when setting the Expires property of the collection.
do you want cookies to expire on a specific date. Far more often you want your
cookies to expire a certain number of days, weeks, or months in the future. Lets
say that you wanted to set the cookie MyCookie to expire in a week from the current
.Cookies (MyCookies).Expires = Date + 7
in mind that cookies can only be read by a specified web site. There is a Domain
Property that you can set using the Response.Cookies collection. This property,
which is equal to your web sites domain name by default, allows you to enter
a different domain name.
path property also determines how cookies can read. This property can be set to
allow cookies to only be read by ASP pages in certain directories. By default
, this property is set to your web sites root directory, which allows cookies
created by an ASP page existing in any directory to be read by an ASP page existing
in any directory.
is strongly suggested that you do not change or alter the Domain or path properties.
If you leave both properties as the defaults, you will have no trouble reading
the cookies youve created on your web site. If you set your Domain or path
incorrectly, you may not be able to successfully read the cookies you write on
your clients computer. Yet another property is the secure property.
write-only, Boolean property determines whether a cookie will be sent through
a non secure protocol. If this property is set to true, the cookies will only
be sent when accessing a pace using the HTTPS protocol. If this property is set
to false, its default value, then the cookie will be transmitted over both HTTP
to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.
: We never rent, trade, or sell my email lists to
We assure that your privacy is respected
.NET Programming Tutorial Homepage