DevCity.NET - http://devcity.net
Book Review: ASP.NET 2.0 Website Programming
http://devcity.net/Articles/221/1/article.aspx
Ged Mead

Ged Mead (XTab) is a Microsoft Visual Basic MVP who has been working on computer software and design for more than 25 years. His journey has taken him through many different facets of IT. These include training as a Systems Analyst, working in a mainframe software development environment, creating financial management systems and a short time spent on military laptop systems in the days when it took two strong men to carry a 'mobile' system.

Based in an idyllic lochside location in the West of Scotland, he is currently involved in an ever-widening range of VB.NET, WPF and Silverlight development projects. Now working in a consultancy environment, his passion however still remains helping students and professional developers to take advantage of the ever increasing range of sophisticated tools available to them.

Ged is a regular contributor to forums on vbCity and authors articles for DevCity. He is a moderator on VBCity and the MSDN Tech Forums and spends a lot of time answering technical questions there and in several other VB forum sites. Senior Editor for DevCity.NET, vbCity Developer Community Leader and Admin, and DevCity.NET Newsletter Editor. He has written and continues to tutor a number of free online courses for VB.NET developers.

 
by Ged Mead
Published on 4/25/2006
 
   Marco Bellinaso's latest book takes an approach that is unlike many other ASP.NET books.   Instead of showing fragmented examples for individual pages or features, the example in this book is an integrated end-to-end site (written in C#). The entire book and site has been written specifically for ASP.NET 2.0, to use the ASP.NET 2.0 features wherever they make sense.

Book Description

ASP.NET 2.0 Programming: Problem Design Solution is aimed at describing, designing, and implementing a site much like the ones you’re probably working on or will be soon, while taking the opportunity to introduce and explain many of the new features that the new great ASP.NET 2.0 framework offers. Difficult problems are addressed head-on so you'll be ready for most of the problems you’ll typically face when writing a modern website, and have one or more solutions ready for them.

Unlike many other ASP.NET books that show examples for individual pages or features, the example in this book is an integrated end-to-end site (written in C#). The entire book and site has been written specifically for ASP.NET 2.0, to use the ASP.NET 2.0 features wherever they make sense.

The end-result is a website which features a layout with user-selectable themes, a membership system, a content management system for publishing and syndicating articles and photos, polls, mailing lists, forums, an e-commerce store with support for real-time credit card processing, homepage personalization, and localization. The book leads the reader through development of a site with:

  • Account registration, personalization and theming
  • News and events, organized into categories
  • Opinion polls
  • Newsletter
  • Forums
  • E-commerce store with shopping cart and order management
  • Localization
Administration of a site will be covered including:
  • Full online back-end administrative section, to manage practically all data from an intuitive user interface
  • Site deployment
In building these site features, you'll learn these new ASP.NET 2.0 features:
  • Master pages
  • Theming
  • Personalization & Web parts
  • Membership & Profile modules
  • Personalization
  • The new server-side UI controls such as GridView, DetailsView, FormView, Wizard, MultiView, the new xxxDataSource and navigation controls, among others.
  • The new compilation mode and deployment modes
  • The new framework for instrumenting the site, as well as handling & logging exceptions
  • The new ADO.NET 2.0 features (e.g. caching with database dependency)
  • The new classes for easy distributed transactions Management
Click here to browse online the sample TheBeerHouse website!

 

Foreword

Foreword by Francesco Balena (Microsoft RD, MS Press author, and .Net2TheMax's founder)

The opportunity of writing a foreword is always a great honor, but if the author is someone I have worked elbow-to-elbow with, then it’s more than an honor: it’s a great pleasure!

I am sure you readers are eager to read the real stuff in following chapters and aren’t very interested in when and how I met Marco a few years ago, but I believe this story is worth telling.

In late ‘90s I started www.vb2themax.com, a Web site that become quickly popular among VB6 aficionados. After a few months Marco began to email me his articles, and it was soon clear to me that I had to do with a smart developer who also had the rare gift of being able to put his experience down in words.

After a couple of years, I decided to write a commercial VB6 add-in and asked Marco to give me a hand. Marco accepted and in a few months we could launch VBMaximizer, a product which was later voted among the best productivity tools by the readers of Visual Basic Programmer’s Journal (now Visual Studio Magazine). The noteworthy detail of this story is that Marco and I worked on this project exclusively via email, without even talking to each other on the phone. I never needed to explain him what I needed and, unbelievably, the code I got from him was virtually defect-free at the first attempt! At the time I didn’t know that Marco was only about 20, otherwise I would have been far more impressed!

I physically met Marco only a few years later and since then we have worked together on many other software projects. Nevertheless, I continue to be pleasingly surprised by the professionalism he puts in everything he does, be it a program, a conference session, an article, or an entire book. Marco is among the few people I know who doesn’t really care for how long it takes to complete a task, provided that the result is something he can be proud of. And the book you’re reading is surely something he can be proud of!

As the author explains in his own introduction, this book is different from most others you can find in bookstores. Most offerings in this area are mainly reference books that dissect every little detail of version 2.0 of ASP.NET or the .NET Framework and that – in the best cases – provide a short listing to illustrate each feature. (I should be familiar with these books very well, having written many reference books myself…)

Marco’s book has a radically different approach: he explains how you can assemble all ASP.NET 2.0’s features and leverage its power to design, develop, and deploy a full-featured Web site. Don’t be fooled by the TheBeerHouse being a fictitious site for a fictitious customer: if the main differences between a sample application and a real-world Web site are the performance, security, robustness, scalability, and care for details that you expect from a commercial site, then Marco’s TheBeerHouse is more real-world than most real-world sites I have seen recently.

In fact, unlike most real site authors, Marco was able to take all the time he needed to implement an impressive list of features and fix all the bugs he bumped into. And unlike most sample application authors, he never took a shortcut and never ignored the problems that developers have to solve every day in the real world. The chapter on the articles/news management and the one on e-commerce took him longer than any other portion of the book. For sure, the overall quality exceeds what you might expect from a mere “book sample” and, as of this writing, it’s the best demonstration of ASP.NET 2.0’s new features, including Microsoft’s own starter kits.

From a teaching perspective, the great value of this book is the rationale underlying all the design and implementation decisions taken in the development phase. Marco does more than just describing what he did: he lists the pros and cons of all the alternatives he tried out and explains how he found the perfect solution (or the best compromise) to each problem. It’s like having an expert sitting besides you, able to read your mind, and ready to fix your mistakes before you have a chance to make them. Can you ask for more?

-- Francesco Balena

 

Chapter Excerpts
The following excerpt is taken from Chapter 4 - Setting Up and Using User profiles"


In the ASP.NET 1.x days, if you wanted to associate a profile to a registered user, you typically added a custom table to your database, or stored them together with the user credentials, in the same table. You also had to write quite a lot of code for the business and data access layers, to store, retrieve, and update that data from your web pages. ASP.NET 2.0 provides a built-in mechanism to manage user profiles, in an easy, yet very complete and flexible, way. This new feature can save you hours or even days of work! The Profile module takes care of everything—you just need to configure what the profile will contain, i.e., define the property name, type, and default value. This configuration is done in the root web.config file, within the <profile> section. The following snippet shows how to declare two properties, FavoriteTheme of type String, and BirthDate of type DateTime:

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

   <system.web>

      <profile>

         <properties>

            <add name="FavoriteTheme" type="String" />

            <add name="BirthDate" type="DateTime" />

         </properties>

      </profile>

   <!-- other settings... -->

   </system.web>

</configuration>

Amazingly, this is all you need to do to set up a profile structure! When the application is run, the ASP.NET runtime dynamically adds a Profile property to the Page class, which means you will not find such a property in the Object Browser at design time. The object returned is of type ProfileCommon (inherited from System.Web.Profile.ProfileBase); you will not find this class in the Object Browser either, or on the documentation, because this class is generated and compiled on-the-fly, according to the properties defined in the web.config file. The result is that you can just access the page’s Profile property and read/write its subproperties. The following code demonstrates how to read the values of the current user’s profile to show them on the page when it loads, and then updates them when a Submit button is clicked:

protected void Page_Load(object sender, EventArgs e)

{

   if (!this.IsPostBack)

   {

      ddlThemes.SelectedValue = this.Profile.FavoriteTheme;

      txtBirthDate.Text = this.Profile.BirthDate.ToShortDateString();

   }

}

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

protected void btnSubmit_Click(object sender, EventArgs e)

{

   this.Profile.FavoriteTheme = ddlThemes.SelectedValue;

   this.Profile.BirthDate = DateTime.Parse(txtBirthDate.Text);

}

Even though you can’t see these properties in the Object Browser, Visual Studio .NET is smart enough to compile this class in the background when the web.config file is modified, so you get full IntelliSense in the IDE, just as if the Profile properties were built-in properties of the Page class, like all the others. Figure 4-11 is a screenshot of the IDE with the IntelliSense in action.

<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><o:lock aspectratio="t" v:ext="edit"></o:lock> 

Figure 4-11

Having a class dynamically generated by Visual Studio 2005 with all the custom profile properties (and the IntelliSense for them) doesn’t just speed up development, but also helps developers reduce inadvertent coding errors. In fact, this class provides strongly typed access to the user’s profile, so if you try to assign a string or an integer to a property that expects a date, you’ll get a compile-time error so you can correct the problem immediately!

When you define a profile property, you can also assign a default value to it, by means of the defaultValue attribute:

<add name="FavoriteTheme" type="String" defaultValue="Colorful" />

The default value for strings is an empty string, not null, as you may have thought. This makes it easier to read string properties, because you don’t have to check whether they are null before using the value somewhere. The other data types have the same default values that a variable of the same type would have (e.g., zero for integers).

When you declare profile properties, you can also group them into subsections, as shown below:

<profile>

   <properties>

      <add name="FavoriteTheme" type="String" />

      <add name="BirthDate" type="DateTime" />

      <group name="Address">

         <add name="Street" type="String" />

         <add name="City" type="String" />

      </group>           

   </properties>

</profile>

The Street property will be accessible as Profile.Address.Street. Note, however, that you can’t define nested groups under each other, but can only have a single level of groups. If this limitation is not acceptable to you, you can define your own custom class with subcollections and properties, and reference it in the type attribute of a new property. In fact, you are not limited to base types for profile properties; you can also reference more complex classes (such as ArrayList or Color), and your own enumerations, structures, and classes, as long as they are serializable into a binary or XML format (the format is dictated by the property’s serializeAs attribute).

The Profile system is built upon the provider model design pattern. ASP.NET 2.0 comes with a single built-in profile provider that uses a SQL Server database as a backing store. However, as usual, you can built your own providers or find them from third parties.

 

Other Excerpts from the book can be found here

 

Summary

    Francesco Balena really says it all in his introductory comments:

 

    From a teaching perspective, the great value of this book is the rationale underlying all the design and implementation decisions taken in the development phase. Marco does more than just describing what he did: he lists the pros and cons of all the alternatives he tried out and explains how he found the perfect solution (or the best compromise) to each problem. It’s like having an expert sitting besides you, able to read your mind, and ready to fix your mistakes before you have a chance to make them. Can you ask for more?