Chapter 1: Introduction to ASP.NET 2.0 1
A Little Bit of History 2
The Goals of ASP.NET 2.0 2
Developer productivity 3
Administration and management 6
Performance and scalability 7
Device-specific code generation 8
Additional New Features of ASP.NET 2.0 9
New developer infrastructures 9
New compilation system 15
Additions to the page framework 15
New objects for accessing data 18
New server controls 18
A New IDE for Building ASP.NET 2.0 Pages 19
Summary 21
Introduction to ASP.NET 2.0
The evolution of ASP.NET continues! The progression from Active Server Pages 3.0 to ASP.NET 1.0
was revolutionary, to say the least — and I am here to tell you that the evolution from ASP.NET
1.0/1.1 to ASP.NET 2.0 is just as exciting and dramatic.
The introduction of ASP.NET 1.0 changed the Web programming model, but ASP.NET 2.0 is just as
revolutionary in the area of productivity. The primary goal of ASP.NET 2.0 is to enable you to
build powerful, secure, and dynamic applications using the least possible amount of code. This
book focuses on the astounding new capabilities that are built into ASP.NET 2.0.
In writing this book, I assume that you are already familiar with ASP.NET 1.0 or 1.1.
I do not cover the basic functionality of ASP.NET provided by those releases.
This book focuses on the Beta 1 release of ASP.NET 2.0. A beta release is a software release that
comes out prior to the final release of the product (the final release is often referred to as the RTM
or Release to Manufacturer version). Software companies sometimes release products early as betas
in hopes that the programming community will demand the features and capabilities that the
release offers. The vendors also hope that the beta version will reveal any bugs in the product
prior to the release of the RTM version. Therefore, be aware that you might encounter errors or
bugs as you code your applications in the ASP.NET 2.0 beta release. Also be aware that the
method or parameter names might change between the beta version and the RTM version. You
may have to rework any ASP.NET applications built using the ASP.NET 2.0 beta when the RTM
version is released. A beta, however, gives you an outstanding opportunity to gain early insight
into the direction a new technology is going and to get up to speed on its use, even before it is
released.
A Little Bit of History
ASP.NET 2.0 has its roots in an older Web technology from Microsoft, which was called Active Server
Pages — or ASP for short. ASP was a quick and easy way to develop Web pages. ASP pages consisted of
a single page that contained a mix of languages. The power of ASP was that you could use VBScript or
JScript code instructions in the pages that would then be executed on the Web server prior to the page
being sent to the end user’s Web browser. This was an easy way to create dynamic Web pages that could
be customized based on parameters dictated by the developer.
ASP 2.0 and 3.0 were quite popular because this technology made it relatively straightforward and easy
to create Web pages. Also, ASP 2.0 and 3.0 appeared in the late ‘90s, just as the dotcom era was born.
During this time, a mountain of new Web pages and portals were developed. ASP was one of the leading
technologies that individuals and companies used to build them. In fact, even today, you can still find a
lot of .asp pages on the Internet — including some of Microsoft’s own Web pages.
But even at the time of the final release of Active Server Pages, in late 1998, Microsoft employees Marc
Anders and Scott Guthrie had other ideas. Their ideas generated what they called XSP (which was an
acronym with no meaning) — a new way of creating Web applications in an object-oriented manner
instead of the interpreted manner of ASP 3.0. They showed their idea to many different groups within
Microsoft, and it was quite well received. In the summer of 2000, the beta of what then was called ASP+
was released at Microsoft’s Professional Developers Conference where the attendees eagerly started
working with it. When the technology became available (with the final release of the .NET Framework
1.0), it was renamed ASP.NET — receiving the .NET moniker that most of Microsoft’s new products
were receiving at that time.
In the summer of 2000, and throughout the entire beta program for ASP+, this outstanding new technology
created excitement. At this point, the entire .NET Framework was rather immature. The code for the
entire Framework came on a single CD. No IDE came with it to enable development of ASP+ pages. To
create your pages and code-behind classes, you had to use Microsoft’s Notepad and the command-line
compilers contained on the CD. I am happy to say that even today — in ASP.NET 2.0 — you can still
use this simple approach to code your applications if you want!
Just working with the first ASP.NET beta was exciting; it is no different with the beta this time around.
Nothing is better than getting your hands on a new technology and seeing what is possible. The following
section discusses the goals of ASP.NET 2.0. See what you can expect from this new beta.
The Goals of ASP.NET 2.0
ASP.NET 2.0 is a major release of the product and is a built-in part of the .NET Framework 2.0. This
release of the Framework is code-named Whidbey. You might hear others referring to this release of
ASP.NET as ASP.NET Whidbey. ASP.NET 2.0 heralds a new wave of development that should eliminate
any of the remaining barriers to adopting this new way of coding Web applications.
When the ASP.NET team started working on ASP.NET 2.0, it had specific goals to achieve. These goals
focused around developer productivity, administration and management, performance and scalability,
and the capability to target any device. They were completely achieved with this milestone product
release. The next sections take a look at each of these goals.
Developer productivity
Much of the focus of ASP.NET 2.0 is on productivity. Huge productivity gains were made in going from
ASP 3.0 to ASP.NET — could there possibly be much more left to gain?
One goal the development team had for ASP.NET 2.0 was to eliminate much of the intense coding that
ASP.NET required and to make ASP.NET tasks easier. The ASP.NET team developing ASP.NET 2.0 had
the goal of reducing by two-thirds the number of lines of code required for an ASP.NET application! It
succeeded in this release, and you will find it literally amazing how quickly you can create an application
in ASP.NET.
The new developer productivity capabilities are the focus of much of the book, so you can find examples
on almost every page. But first, take a look at the older technology. In Listing 1-1, you use ASP.NET 1.0
to build a table in a Web page that includes simple paging of the data.
Listing 1-1: Showing data in a DataGrid server control with paging enabled (VB only)
<%@ Page Language=”VB” AutoEventWireup=”True” %>
<%@ Import Namespace=”System.Data” %>
<%@ Import Namespace=”System.Data.SqlClient” %>
<script runat=”server”>
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs)
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Private Sub BindData()
Dim conn As SqlConnection = New SqlConnection(“server=’localhost’;
trusted_connection=true; Database=’Northwind’”)
Dim cmd As SqlCommand = New SqlCommand(“Select * From Customers”, conn)
conn.Open()
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds, “Customers”)
DataGrid1.DataSource = ds
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
DataGrid1.CurrentPageIndex = e.NewPageIndex
BindData()
End Sub
</script>
<html>
Listing 1-1: (continued)
<head>
</head>
<body>
<form runat=”server”>
<asp:DataGrid id=”DataGrid1” runat=”server” AllowPaging=”True”
OnPageIndexChanged=”DataGrid1_PageIndexChanged”></asp:DataGrid>
</form>
</body>
</html>
Although quite a bit of code is used here, this is a dramatic improvement over what was required to
accomplish this task using Active Server Pages 3.0. I won’t go into the details of the code; I just want to
demonstrate that in order to add additional common functionality (such as paging) for the data shown
in a table, the developer had to create custom code.
This is one area where the new developer productivity gains are most evident. ASP.NET 2.0 now provides
a new control called the GridView server control. This control is much like the DataGrid server
control that you may already know and love, but the GridView server control contains the built-in capability
to apply paging, sorting, and editing of data with relatively little work on your part (besides offering
many more new features). Look at an example of the GridView server control in Listing 1-2. This
example builds a similar table of data from the Customers table in the Northwind database that now
includes paging.
Listing 1-2: Viewing a paged dataset with the new GridView server control
<%@ page language=”VB” %>
<script runat=”server”>
</script>
<head id=”Head1” runat=”server”>
<head runat=”server”>
<title>GridView Demo</title>
</head>
<body>
<form runat=”server”>
<asp:GridView ID=”GridView1” Runat=”server” AllowPaging=”True”
DataSourceId=”Sqldatasource1” />
<asp:SqlDataSource ID=”SqlDataSource1” Runat=”server”
SelectCommand=”Select * From Customers”
ProviderName=”System.Data.OleDb”
ConnectionString=”Provider=SQLOLEDB;Server=localhost;uid=sa;
pwd=password;database=Northwind” />
</form>
</body>
</html>
That’s it! You can apply paging by using a couple of new server controls. You turn on this capability
using a server control attribute, the AllowPaging attribute of the GridView control:
<asp:GridView ID=”GridView1” Runat=”server” AllowPaging=”True”
DataSourceId=”Sqldatasource1” />
The other interesting event occurs in the code section of the document:
<script runat=”server”>
</script>
These two lines of code aren’t actually needed to run the file, but I include them here to make a point —
you don’t need to write any server-side code to make this all work! You only have to include some server controls:
one control to get the data and one control to display the data. The controls are then wired
together. Running this page produces the results shown in Figure 1-1.
This is just one of thousands of possible examples, so at this point you can’t possibly grasp how much
more productive you can be with ASP.NET 2.0. As you work through the book, however, you will see
plenty of examples that demonstrate this new level of productivity.
Administration and management
The initial release of ASP.NET focused on the developer, and little was geared toward the people who
had to administer and manage all the ASP.NET applications that were built. Instead of working with
consoles and wizards as they did in the past, administrators and managers of these new applications
now had to work with XML configuration files such as machine.config and web.config.
To remedy this situation, ASP.NET 2.0 now includes a Microsoft Management Console (MMC) snap-in
that enables Web application administrators to easily edit configuration settings on the fly. Figure 1-2
shows the ASP.NET Configuration Settings dialog open on one of the available tabs.
This dialog allows system administrators to edit the contents of the machine.config and the web.
config files directly from the dialog instead of having to examine the contents of an XML file.
In addition to this dialog, Web or system administrators have another way to administer their ASP.NET
2.0 applications — using the new Web Administration Tool shown in Figure 1-3.
You might be asking yourself how you can access these new tools. Well, that is the exciting part. These
tools are built off new APIs that are now part of the .NET Framework 2.0 and which are open to you as a
developer. These new APIs give you programmatic access to many of the configurations of your Web
applications. You now have programmatic access to reading and writing to .config files, enabling you
to create similar tools or even deployment and management scripts.
In addition to these new capabilities, you now also have the capability to easily encrypt sections of your
configuration files. In the past, many programmers stored vital details — such as usernames, passwords,
or even their SQL connection strings — directly in the web.config file. With the capability to
easily encrypt sections of these files, you can now store these items in a more secure manner.
Performance and scalability
One of the goals for ASP.NET 2.0 was to provide the world’s fastest Web application server. ASP.NET 2.0
includes a number of performance enhancements that are addressed throughout this book.
One of the most exciting performance enhancements is the new caching capability aimed at Microsoft’s SQL Server. ASP.NET 2.0 now includes a feature called SQL cache invalidation. Before ASP.NET 2.0,
it was possible to cache the results that came from SQL Server and to update the cache based upon a time interval — for example, every 15 seconds or so. This meant that the end user might see stale data if the result set changed sometime during that 15-second period.
In some cases, this time interval result set is unacceptable. In an ideal situation, the result set stored in
the cache is destroyed if any underlying change occurred in the source from which the result set was
retrieved — in this case, SQL Server. With ASP.NET 2.0, you can make this happen with the use of SQL
cache invalidation. This means that when the result set from SQL Server changes, the output cache is
triggered to change, and the end user always sees the latest result set. The data presented is never stale.
Another big area of change in ASP.NET is in the area of performance and scalability. ASP.NET 2.0 now
provides 64-bit support. This means that you can now run your ASP.NET applications on 64-bit Intel or
AMD processors.
Because ASP.NET 2.0 is fully backward compatible with ASP.NET 1.0 and 1.1, you can now take any former
ASP.NET application, recompile the application on the .NET Framework 2.0, and run it on a 64-bit
processor.
Device-specific code generation
If you thought that building device applications with ASP.NET 1.0 or 1.1 was easy in the past, wait until
you see how you accomplish this in ASP.NET 2.0. ASP.NET 1.0 gave you the capability to build mobile
applications through the additional download of the Microsoft Mobile Internet Toolkit (MMIT). With
ASP.NET 1.1, this was included by default and, therefore, didn’t require the download. It did, however,
still require the use of <mobile:> server controls instead of the standard <asp:> server controls that
ASP.NET provided.
With ASP.NET 2.0, you no longer use the <mobile:> server controls. All the <asp:> server controls now
have the capability to output to various devices and not just the big browsers, such as Microsoft Internet
Explorer or Opera. The <asp:> server controls can now output not only in HTML, but also in XHTML,
CHTML, or WML (see Figure 1-4).
*****本书38页,章节第9页*****