Monday, March 29, 2010

What is a Cookie? & How to Create a Cookie?

A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With ASP, you can both create and retrieve cookie values.

How to Create a Cookie?
The "Response.Cookies" command is used to create cookies.
Note: The Response.Cookies command must appear BEFORE the tag.
In the example below, we will create a cookie named "firstname" and assign the value "Alex" to it:
<% Response.Cookies("firstname")="Alex" %>
It is also possible to assign properties to a cookie, like setting a date when the cookie should expire:
<% Response.Cookies("firstname")="Alex" Response.Cookies("firstname").Expires=#May 10,2012# %>

Everything you need to know about cookies: How to create them, make them, bake them