Datasheet

Listing 1-5 (continued)
ContentPlaceHolderID=”ContentPlaceHolder1”
Runat=”Server”>
<h2>This is my content.</h2>
</asp:Content>
The two interesting parts of Listing 1-5 are the MasterPageFile attribute and the Content element. The
Page directive contains a new attribute named MasterPageFile, specifying the filename of the Master
Page to use.
It is evident from Listing 1-5 that content pages don’t have HTML markup as normal Web Forms do.
Instead, add a Content element that identifies where to place content markup within the Master Page by
specifying the id of the contentplaceholder (in the Master Page) to use with the ContentPlaceHolderID
attribute. Only the markup in the Content element appears in the Master Page.
Because you don’t have normal HTML markup, such as a Head, set the Title attribute of the Page direc-
tive with what you would have normally put into the Head title element.
This shows how elegant and simple it is to use Master Pages in ASP.NET v2.0. Supported by VS 2005, it
is a much easier solution than ASP.NET v1.1 hacks.
URL Rewriting
URL rewriting is the practice of accepting URLs with meaningful naming conventions and translating
them into real query strings. A couple of reasons why you would want meaningful naming conventions
include the capability to organize information into a logical hierarchy or to mask query string parame-
ters. In this section I’ll show you how URL rewriting can improve your user interface, describe the old
and new ways to accomplish URL rewriting, and give you some code that demonstrates the concept.
Why URL Rewriting?
An example of hierarchical organization could be described by looking at how a blog is organized by
time. From the user’s perspective, the following query string could be considered very cryptic:
http://www.someblogsite.com/username/?y=2005&m=01&d=31
The preceding query string returns blog entries for January 1, 2005, which isn’t easy to determine. You
could modify code so that the parameters were more meaningful, such as this:
http://www.someblogsite.com/username/?year=2005&month=01&day=31
I also add some extra code in this section to demonstrate best practices in n-tier
architecture and data handling, rather than cheat with a simpler datasource control.
14
Chapter 1
04_597663 ch01.qxp 4/25/06 9:54 PM Page 14