Websites typically use session cookies to ensure that users are recognized when they move from page to page within one site and that any information you have entered is remembered. For example, if an e-commerce site which uses session cookies then items placed in a shopping cart would appear by the time you reach the checkout. We will introduce you how to work with the cookies in ASP.NET 2.0 and VB.NET in this tutorial.

The browser is responsible for managing cookies on a user system. Cookies are sent to the browser via the HttpResponse object that exposes a collection called Cookies. You can access the HttpResponse object as the Response property of your Page class. Any cookies that you want to send to the browser must be added to this collection. When creating a cookie, you specify a Name and Value.

When a browser makes a request to the server, it sends the cookies for that server along with the request. In this ASP.NET applications, we can read the cookies using the HttpRequest object, which is available as the Request property of Page class.

We added one text box, two buttons and 1 label to the web page. The text box is used for inputting the information of cookie. By clicking Add button, the sample application will create a new cookie. By clicking View button, you will see the cookie created. The expiration date of cookie will be set to 2006-10-1.

We chose Server Intellect for its dedicated servers, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.

The front end Default.aspx page looks something like this:

The flow for the code behind page is as follows.

Download Source Files