Home Page

The application's home page is contained in the Default.aspx file. Most of the page consists of static HTML. There are, however, three components that are referenced by this page that encapsulate the real work. These components are for the header, menu, and popular items.

A single server component Label object named WelcomeMsg is on the home page. This object contains the user's full name if he has at one time logged in at this machine. When a user logs in, a cookie persists his full name on the client machine. The following code shows how the Welcome Msg object is created from the cookie. It checks for the existence of a cookie named IBuySpy_FullName, and if it is found, the value in it is placed into the WelcomeMsg.Text property.

 void Page_Load(Object sender, EventArgs e) {   // Customize welcome message if personalization cookie is present   if (Request.Cookies["IBuySpy_FullName"] != null) {     WelcomeMsg.Text =       "Welcome " + Request.Cookies["IBuySpy_FullName"].Value;   } } 

The Classifieds application in Chapter 7 uses cookies more extensively. If you haven't read Chapter 7 and want more information about cookies, read through that chapter.

TIP: It's sometimes easier to use session variables than cookies. Session variables can require a bit less code, and they usually seem easier to use. But the choice of whether to use cookies or session variables isn't a simple one.

Session variables expire after a set period of time (20 minutes by default). This may be the desired behavior if you don't want users to keep your Web application open indefinitely. Cookies can time out, but they don't have to (you can set their Expires property to DateTime.MaxValue). This is the first part of the decision: value persistence.

Another consideration is that session variables require server resources such as memory and CPU cycles. Cookies require client memory and CPU cycles. If you are concerned with your server's resources, you might want to consider cookies instead of session variables.

Scalability is enhanced with cookies (over session variables) because more users don't require more server resources the work is on the client machine. One issue of which you need to be aware is the reluctance of some users to allow cookies on their machines. You'll have to 1) insist that users allow cookies, 2) use another mechanism such as session variables, or 3) dynamically choose the mechanism at runtime according to whether a user's browser allows cookies.

The application's home page looks like a typical e-commerce site. It lists product categories, a featured product, and a list of popular products. You can see the home page in Figure 8.1

Figure 8.1. The Main Page Shows Product Categories, a Featured Product, and a Popular Items List.


Just to make sure you can see where the three components are located on the screen, Figure 8.2 shows their locations.

Figure 8.2. This Figure Shows the Location of the Three Components.


Because this is the page that's seen most frequently in the IBuySpy Store application, performance is important. For this reason, two of the components, the Menu and the PopularItems components, are cached. They query the database once every hour for the content that they display. Chapter 4 talks at length about the Cache API. Refer to this chapter for a complete explanation. Caching saves tremendously on the CPU time that would have been spent querying the database without it.

Another big performance gain (that we've already talked about some) is the fact that the personalization is done with a client-side cookie. This way, the user's name will appear on the page with very little server-side processing.

ASP. NET Solutions - 24 Case Studies. Best Practices for Developers
ASP. NET Solutions - 24 Case Studies. Best Practices for Developers
ISBN: 321159659
Year: 2003
Pages: 175

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net