first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

MCAD/MCSD Notes: Chapter 7, Lesson 1; Saving and Retrieving User Information

Lesson 1: Saving and Retrieving User Information

The purpose of this lesson is to introduce the concept of user customization features in ASP.NET. User-specific information can be stored on the client as cookies and/or on the server in an XML file managed by ADO and a predefined XML schema. Since this review is written "close" to the next release of Visual Studio, it may help to mention that ASP.NET 2.0 expands on this concept profoundly with a rich set of user customization features.

This lesson suggests two ways to design with cookies: store all information in the cookie, being aware of the 4096-byte limit or store a GUID in the cookie which is used to retrieve user, server data. In either case, the design features a check for client-support of cookies with the Boolean in Request.Browser.Cookies and, optionally, setting the expiration date of the cookies with the DateTime.Now.AddDays() method.

This implies that Response.Cookies["lastVisit"] is not equal to Response.Cookies["LastVisit"].

Remove a cookie by setting the Expires property to DateTime.Now.

The code sample demonstrates:

HttpCookie cookie = (Request.Cookies["userID"] != null) ?
    Request.Cookies["userID"]
        : new HttpCookie("userID",System.Guid.NewGuid.ToString());

Visual Studio .NET provides XML and XSD editors to create XML files for use with DataSet objects when the formality of a database seems unnecessary. Defining a schema with an ID element that will store our GUID, allows us to use the DataSet.ReadXmlSchema() method to automatically create a DataTable that is compatible with our external XML file.

The "SaveXML method" does not exist among the members of DataSet, so evidently this is an editorial error. The code sample that follows this error clearly suggests that we use the DataSet.WriteXML() method.

mod date: 2005-06-29T05:12:33.000Z