Databases and Cookies - Resetting a Cookie
(Page 10 of 13 )
There are two cases for setting a cookie. The first is that no cookie existed because the person was never registered, that is, they have no record in the database. But a frequent second type of case is that a person has a record in the People table but they have lost their cookie. This could be for many reasons, as discussed earlier in the chapter. In this case we want to reset a cookie.
In this second case, it is nice to give people a way to reset their cookie quickly and easily, without reentering all of their information in the People table. In fact, we specifically want to avoid the latter since re-entering their data could easily lead to duplicate records for people.
In other words, we don't want to enter this person as a new record in the database like we would when first setting a cookie; rather we want to identify their existing record in the database and use that to set a cookie.
The solution to the second problem is to build a page that gives cookie-less visitors several options. Firstly, they could pick their name out of a drop-down list of names already in your People table. You can also give the visitor the option of visiting without a cookie. The third is that they can register, which will respond by both adding them as a record in the People table and setting a cookie on their hard drive. A fourth option is to ask the visitor to sign in at the beginning of each visit. The sign-in could be by name, member ID or a field like Email address. Although tedious, some visitors prefer signing in to setting a cookie.
You must also weigh up which options you want to offer in view of your security. In an Internet site, you would not want to reveal the names of all your visitors in a drop-down box. Likewise, with more than a few score members, you could not offer a drop-down list of names, and would have to gather the name by a text field and do a match with the database. But let us cover an example here for a departmental intranet with a few dozen users.
There are four pages or parts of pages that are needed for this process:
- First, our cookie-using home page must be modified to detect a missing cookie.
- Second, we must create a form for resetting a cookie, which offers a list of members.
- Third, we need a page that will set a cookie based on the selection in the above page.
- Last, when we reset a cookie, we will provide to the user a confirmation page.
This is from Beginning ASP Databases by Kauffman, Spencer, and Willis (Apress, ISBN 1590592492). Check it out at your favorite bookstore today.
Buy this book now. |
Next: Try It Out – Resetting a Cookie >>
More ASP.NET Articles
More By Apress Publishing