Datasheet
<add url=”~/2006/01”
mappedUrl=”~/MonthView.aspx?year=2006&month=01”/>
<add url=”~/2006/02”
mappedUrl=”~/MonthView.aspx?year=2006&month=02”/>
<add url=”~/2005”
mappedUrl=”~/YearView.aspx?year=2005”/>
<add url=”~/2005/01”
mappedUrl=”~/MonthView.aspx?year=2005&month=01”/>
<add url=”~/2005/02”
mappedUrl=”~/MonthView.aspx?year=2005&month=02”/>
</urlMappings>
<compilation debug=”true”/>
</system.web>
</configuration>
In each one of the add elements of Listing 1-9, the hackable URL translates into a mappedUrl, which is
the actual address and query string sent to the page. The tilde (
~) symbol represents the application
directory that each page is relative to. You must use
& in place of just the & symbol to separate
parameters. We’ve left out entries for some months to shorten the listing.
To see the list of articles, users select the month they are interested in. Listing 1-10 shows how
MonthView
.aspx
is implemented. I used the GridView control in Listing 1-10 because I needed to format the output
nicely for multiple data rows and I wanted to bind it to the ObjectDataSource control. The GridView
control is a new control added to ASP.NET in v2.0 that replaces the DataGrid control.
Listing 1-10: Using the GridView to read query parameters: MonthView.aspx
<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”MonthView.aspx.cs”
Inherits=”MonthView” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” >
<head runat=”server”>
<title>Articles for the Month</title>
</head>
<body>
<form id=”form1” runat=”server”>
<h1>
Requested Articles:</h1>
<br />
<asp:GridView ID=”GridView1” runat=”server”
AutoGenerateColumns=”False” DataSourceID=”ArticlesODS”>
<Columns>
<asp:BoundField DataField=”Year”
HeaderText=”Year” SortExpression=”Year” />
<asp:BoundField DataField=”Month”
HeaderText=”Month” SortExpression=”Month” />
<asp:BoundField DataField=”Title”
HeaderText=”Title” SortExpression=”Title” />
<asp:BoundField DataField=”Content”
HeaderText=”Content” SortExpression=”Content” />
(continued)
19
Hacks Revisited
04_597663 ch01.qxp 4/25/06 9:54 PM Page 19