Beginning Active Server Pages


First of all, what are cookies? No, we're not talking about the sort you eat! Cookies are small pieces of information saved by the browser enabling websites to remember your preferences (good), login information (hmm...), or track your movements across the site (bad!).

Whatever your view on cookies, ASP provides full support for them, enabling you, the webdesigner, to make the most out of them if you so wish.

A word of caution. Do not assume that your visitor will quite happily accept the cookies...although no longer the default setting, web browsers still allow users (quite rightly) to block cookies, and you should provide an alternative!

To save a value to a cookie, simply use this syntax:

Response.Cookies("CookieName") = Value

Once the cookie is saved, you can access it by using

Variable = Request.Cookies("CookieName")

Note, however, that you cannot access the cookie from the same page you saved it on. So, for example,

Response.Cookies("username") = Request.Form("username")
Response.Write "hello " & Request.Cookies("username")

would not work! Of course, if you re-load the same page after the cookie has been saved, you will get access to that cookie.

You might also like...


About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“God could create the world in six days because he didn't have to make it compatible with the previous version.”