ASP - Using Cookies

To createa new cookie, use a statement such as the following:

<%
Response.Cookies("User")="John"
%>

This statement created a new cookie with the name 'User' and set its value to the string 'John'. If a cookie by that name existes already on the client computer, its value is overwritten; if not, a new cookie is created. This cookie is released as soon as the current session ends.

You can specify the expiration date and time with the Expires property of the cookie, as follows:

To read the cookie from the client computer, use the Cookies property of the Request object and specify the desired cookie by name as following:

<%
username = Request.Cookies("User")
%>

The 'username' variable holds the string "John" after the execution of this statement.

Cookie Dictionaries

A cookie dictionary has a name like a regular cookie, and its members have names. To access individual members of the dictionary, use another name. To create a dictionary of cookie use the following statement: