ASP NET by Example 6th Edition Steven A. Smith pdf download
ASP NET by Example 6th Edition Steven A. Smith pdf download
Smith
pdf download
https://ebookgate.com/product/asp-net-by-example-6th-edition-
steven-a-smith/
https://ebookgate.com/product/pro-asp-net-mvc-3-framework-3rd-edition-
steven-sanderson/
ebookgate.com
https://ebookgate.com/product/microsoft-asp-net-4-step-by-step-george-
shepherd/
ebookgate.com
https://ebookgate.com/product/mastering-asp-net-with-vb-net-1st-
edition-a-russell-jones/
ebookgate.com
Pro ASP NET Web API HTTP Web Services in ASP NET 1st
Edition Tugberk Ugurlu
https://ebookgate.com/product/pro-asp-net-web-api-http-web-services-
in-asp-net-1st-edition-tugberk-ugurlu/
ebookgate.com
ASP NET Core 1st Edition Fritz
https://ebookgate.com/product/asp-net-core-1st-edition-fritz/
ebookgate.com
https://ebookgate.com/product/flash-game-development-by-example-
feronato/
ebookgate.com
https://ebookgate.com/product/debugging-asp-net-1st-ed-edition-
jonathan-goodyear/
ebookgate.com
ASP.NET
B Y E X A M P L E
Publisher
ASP.NET by Example David Culverwell
Copyright © 2002 by Que Executive Editor
All rights reserved. No part of this book shall be reproduced, Candy Hall
stored in a retrieval system, or transmitted by any means, elec- Acquisitions Editor
tronic, mechanical, photocopying, recording, or otherwise, with- Michelle Newcomb
out written permission from the publisher. No patent liability is
assumed with respect to the use of the information contained
Development Editors
herein. Although every precaution has been taken in the prepa- Robin Drake
Maureen McDaniel
ration of this book, the publisher and author assume no respon-
Sarah Robbins
sibility for errors or omissions. Nor is any liability assumed for
damages resulting from the use of the information contained Managing Editor
herein. Thomas F. Hayes
International Standard Book Number: 0-7897-2562-2 Senior Editor
Susan Ross Moore
Library of Congress Catalog Card Number: 2001090372
Copy Editors
Printed in the United States of America Margaret Berson
Michael Dietsch
First Printing: December 2001
Indexer
04 03 02 01 4 3 2 1 D&G Limited, LLC
Trademarks Proofreader
D&G Limited, LLC
All terms mentioned in this book that are known to be trade-
marks or service marks have been appropriately capitalized. Technical Editor
Que cannot attest to the accuracy of this information. Use of a Vincent W. Mayfield
term in this book should not be regarded as affecting the validity Team Coordinator
of any trademark or service mark. Cindy Teeters
Media Developer
Warning and Disclaimer Michael Hunter
Every effort has been made to make this book as complete and
Interior Designer
as accurate as possible, but no warranty or fitness is implied.
Karen Ruggles
The information provided is on an “as is” basis. The author(s)
and the publisher shall have neither liability nor responsibility Cover Designer
to any person or entity with respect to any loss or damages Rader Design
arising from the information contained in this book. Page Layout
D&G Limited, LLC
00 71465_FM 11/30/01 10:26 AM Page iii
iii
Contents at a Glance
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
1 Overview .NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7
2 An Introduction to ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19
3 Migrating from ASP to ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . .31
4 The New ADO—ADO.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65
5 HTML/Web Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .109
6 Using ASP.NET List Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . .139
7 Using ASP.NET Rich Controls . . . . . . . . . . . . . . . . . . . . . . . . . . .171
8 Using ASP.NET Validation Controls . . . . . . . . . . . . . . . . . . . . . . .195
9 Using ASP.NET User Controls . . . . . . . . . . . . . . . . . . . . . . . . . . .227
10 ASP.NET Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .247
11 ASP.NET and Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . .275
12 Custom ASP.NET Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .307
13 Debugging ASP.NET Overview . . . . . . . . . . . . . . . . . . . . . . . . . . .343
14 Case Study in Ecommerce with ASP.NET . . . . . . . . . . . . . . . . . .365
A The ASP.NET Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .393
B The ADO.NET Object Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . .405
C VB.NET Programming Reference . . . . . . . . . . . . . . . . . . . . . . . . .459
D C# Programming Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . .489
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .516
00 71465_FM 11/30/01 10:26 AM Page iv
Table of Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
1 .NET Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7
The Big .NET Picture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8
The .NET Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9
Class Orientation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9
Runtime Hosts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10
The Common Language Runtime: A New Interpretation
of Older Technology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11
Intermediate Language and Metadata . . . . . . . . . . . . . . . . .12
The JIT Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15
2 An Introduction To ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19
Moving to .NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20
A Brief History of ASP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21
Why ASP Developers Need This Book . . . . . . . . . . . . . . . . . . . . . .23
Benefits of ASP.NET over ASP . . . . . . . . . . . . . . . . . . . . . . . . . . .24
ASP.NET Is Compiled, not Interpreted . . . . . . . . . . . . . . . . .24
Separation of Code from Content . . . . . . . . . . . . . . . . . . . . .24
No More “DLL Hell” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24
Side-by-Side Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . .25
Real Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25
Real Programming Languages . . . . . . . . . . . . . . . . . . . . . . .25
Real Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .26
Directory-Based Deployment . . . . . . . . . . . . . . . . . . . . . . . . .26
File-Based Application Configuration . . . . . . . . . . . . . . . . . .26
Event-Based Programming Model . . . . . . . . . . . . . . . . . . . .26
Improved, Extensible Object Model . . . . . . . . . . . . . . . . . . .27
More Integrated Functions . . . . . . . . . . . . . . . . . . . . . . . . . .27
Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .28
Performance Improvements . . . . . . . . . . . . . . . . . . . . . . . . .28
Better Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .28
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29
3 Migrating From ASP to ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . .31
Preparing to Use ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32
Basic Differences Between ASP and ASP.NET . . . . . . . . . . . . . . .32
00 71465_FM 11/30/01 10:26 AM Page v
Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32
Maintaining State Between ASP and ASP.NET . . . . . . . . . .33
Language Differences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34
Common ASP Tasks and Their ASP.NET Equivalents . . . . . . . . .36
Read a Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .36
Validate a Form’s Entries . . . . . . . . . . . . . . . . . . . . . . . . . . .42
The Login Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .50
View Results of Database Query . . . . . . . . . . . . . . . . . . . . . .58
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .62
4 The New ADO—ADO.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65
ADO vs. ADO.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .66
The History of Microsoft Data Access . . . . . . . . . . . . . . . . . .66
ADO vs. ADO.NET Object Model . . . . . . . . . . . . . . . . . . . . .68
Connecting to the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . .69
Retrieving Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .70
Using the SqlCommand Object . . . . . . . . . . . . . . . . . . . . . . . . .70
The DataReader Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .72
The SqlDataAdapter Object . . . . . . . . . . . . . . . . . . . . . . . . . . .75
The DataSet Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .79
Data Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .87
The DataGrid Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .87
The Repeater Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .94
The DataList Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .99
Working with XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .102
Generating XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .103
Consuming XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .106
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .107
5 HTML/Web Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .109
What Are Server Controls, Anyway? . . . . . . . . . . . . . . . . . . . . . .110
Why Two Kinds of Controls? . . . . . . . . . . . . . . . . . . . . . . . .110
When Should I Use Each Kind of Control? . . . . . . . . . . . . .111
HtmlControls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .111
HtmlControl Properties and Methods . . . . . . . . . . . . . . . . . .111
HtmlContainerControl Properties . . . . . . . . . . . . . . . . . . . . .114
An HtmlControl Example . . . . . . . . . . . . . . . . . . . . . . . . . .114
HtmlForm Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .117
Table Control Properties . . . . . . . . . . . . . . . . . . . . . . . . . . .118
00 71465_FM 11/30/01 10:26 AM Page vi
vi
vii
viii
ix
xi
xii
xiii
Blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .493
Statement Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .493
Empty Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .493
Labeled . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .493
Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .493
Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .494
Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .494
Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .495
jump . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .496
try . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .497
checked and unchecked . . . . . . . . . . . . . . . . . . . . . . . . . . . . .498
lock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .498
using . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .498
Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .498
Value Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .498
Reference Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .500
Component-Based Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . .512
Namespaces and Assemblies . . . . . . . . . . . . . . . . . . . . . . . .512
Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .513
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .516
00 71465_FM 11/30/01 10:26 AM Page xiv
xiv
xv
using various Microsoft technologies and lately has been heavily involved in
learning and developing on the .NET platform. Nathen can be reached at
grass@rdacustomsoftware.com.
xvi
Dedication
To my wife, Michelle, with my thanks.
00 71465_FM 11/30/01 10:26 AM Page xvii
xvii
Acknowledgments
I would like to thank two Michelles in my life: my wife, Dr. Michelle Smith,
who has put up with many long hours devoted to my computer, and my editor,
Michelle Newcomb. They have both been very patient with me while I have
worked on this, my first print book. It’s been a long road with a few surprises,
and I’ve really appreciated the support. Thanks also to Chris, for many hours of
diversion while I should have been concentrating.
00 71465_FM 11/30/01 10:26 AM Page xviii
xviii
Introduction
2 Introduction
You can also find Microsoft’s ASP.NET and Visual Studio.NET documentation
online at the following Web sites:
ASP.NET: http://www.asp.net/
VS.NET: http://msdn.microsoft.com/vstudio/
Introduction 3
Microsoft marketing hoopla over the last year, but that you haven’t had the
chance to work with any of it yet. We figure you’re reading this book to learn
• How ASP.NET can help you as an Internet application developer to be
more efficient and to build more powerful applications
• How the error handling in ASP.NET allows you to centralize your error
handling into one page
• How ASP.NET will make your existing applications perform better by
using compiled code
• How with ASP.NET a complete programming model is available for appli-
cations that allows for better tools and simpler form handling
4 Introduction
Online Resources
In addition to the contents of this book, you will find additional resources online
at the book’s Web site. The Web site includes online sample code, any updates to
the book that may be necessary, and information for providing feedback or ques-
tions to the book’s authors. You can find the book’s support Web site at:
http://aspauthors.com/aspnetbyexample/
In addition, you will find a number of ASP.NET related Web sites on the inside
of the back cover.
01 71465_INTRO 11/30/01 10:36 AM Page 5
Introduction 5
What’s Next
OK, enough with the preliminary necessities! Let’s take a look at what all the
fuss is about with ASP.NET. In the first chapter, we’ll provide you with an intro-
duction to Microsoft’s new development architecture, the .NET Framework. This
provides the basis for all of ASP.NET (and, indeed, all Microsoft development in
the near term). Following this introduction, we’ll move into learning ASP.NET
in particular.
02 71465_CH01 11/30/01 10:12 AM Page 6
02 71465_CH01 11/30/01 10:12 AM Page 7
1
.NET Overview
“Keep on the lookout for novel ideas that others have used successfully.
Your idea has to be original only in its adaptation to the problem you’re
working on.”
—Thomas Edison
Thomas Edison did not invent the first electric light bulb or the first incan-
descent lamp. He did, however, invent the first practical and commercially
successful electric incandescent lamp. He did not invent the first electrical
power station. He improved the designs of existing generators and regula-
tors to create the first commercially successful power station capable of
delivering affordable power for electric lighting. He did not invent the tele-
graph. But he did invent the first duplex and multiplex telegraphy systems,
enabling telegraphs to send and receive messages at the same time over the
same wire.
Thomas Edison did not invent the Internet, wireless computer devices, or
even .NET. He did, however, create a framework of core technologies that
we have improved that make those technologies possible. .NET is not the
next generation of the Internet. It is the first practical set of tools that will
enable software developers to invent the next generation of the Internet.
.NET is an original adaptation of many successful and novel technologies
and ideas to solve a problem; businesses have found it very difficult and
expensive to create profitable Internet solutions with the available develop-
ment frameworks and architectures. The next generation of the Internet
will be funded by businesses who demand solutions with a short develop-
ment cycle, a quick return on their investment, long-term profitability, and
that are secure and inexpensive to maintain and upgrade.
.NET has been designed with the Internet in mind from the ground up.
.NET absorbs many successful ideas that have been in use for years, yet it
is a radical departure from the client-server framework it replaces. It is
based on time-tested, object-oriented software programming concepts, non-
proprietary standards and protocols, and programming languages that
02 71465_CH01 11/30/01 10:12 AM Page 8
Class Orientation
The .NET Class Library is a huge organized hierarchy of class objects,
shown in Figure 1.1. These objects expose services that you can use to
develop your own services. They include support for things like Windows
Forms and Web Services, as well as objects for working with XML and data.
To include these services in our applications, we navigate the hierarchy
using traditional object-oriented programming principles. Navigating this
hierarchy is a lot like you would navigate hierarchy of files and folders on
your hard drive. For example, if you were referring me to a certain SQL
driver on my system (assuming we have the same OS) you would use some-
thing like “c:\WINNT\System\Data\SQLClient\”. A similar reference
included in your code would look like “System.Data.SQLClient”. The only
difference is that the object-oriented code references separate each level of
the hierarchy with a dot “.” These explicit references to groups of classes
within the Framework’s class libraries are also referred to as namespaces
in .NET. You can think of namespaces as organizing classes just as folders
organize files in a file system.
02 71465_CH01 11/30/01 10:13 AM Page 10
Windows Windows
Web HTTP
Pages Forms Service
Services Handlers
Applications Applications
ASP.NET
.NET Framework
OS
We also use the benefits of a unique class reference so that two objects with
the same name cannot clash. Imagine that you have an application that
allows remote clients to call Web services in your Customers.Customer
object. If that remote client has a local reference to its own version of an
object named Customers.Customer, there will be some major problems for
that remote client. Microsoft recommends that each developer create at
least two unique namespace levels that become the root references for all
their object creations. For example, a much better reference to my applica-
tion’s “Customer class” might look something like this:
“JoesGarage.GlennCook.SimpleCSharp.ASPWebServiceApp.Customers.Customer”
Runtime Hosts
EXAMPLE The last component in the framework that at least deserves an honorable
mention as a “main component” (especially in this book) is a .NET runtime
02 71465_CH01 11/30/01 10:13 AM Page 11
host. A runtime host is an application that loads the .NET runtime into its
process. ASP.NET is an example of an application that loads the runtime
into its process for its Web-related services. Internet Explorer is another
example of a runtime host allowing us to download and execute managed
code within its processes. The last runtime host component included in the
framework is shell executables. This piece is actually what calls the .NET
runtime from your operating system when you want to start a .NET appli-
cation. It will also transfer the control of the .NET application from your
system to the runtime.
“c:/>csc.exe simpleCSharp.cs”
Each programming language has its own compiler. Every one of these com-
pilers must adhere to a common set of strict rules found at the core of the
EXAMPLE CLR. These strict rules ensure that each language’s compiler will produce
the same type of compiled code. Even though your compiled .NET applica-
tion will have the same extension as a traditional Win32-based executable
(that is, EXE or DLL), the internal results of the files are completely differ-
ent. A .NET executable is compiled into what could be described as an “exe-
cutable package” that includes Microsoft’s Intermediate Language (MSIL or
02 71465_CH01 11/30/01 10:13 AM Page 12
Windows Form
Class
assemblies
C# .NET Application
images in VS.NET
X COM+dll
HTML
Compiling Assembly
Metadata
IL Code
simpleCsharpAssembly.dll
Summary 15
Summary
The .NET Framework is the infrastructure that supports an integrated
development and execution platform that allows seamless interoperability
between programs developed in a variety of languages. The framework is
governed by a common yet strict set of standards, which are enforced by the
Common Language Runtime (CLR). These rules are the foundation of
.NET’s multilanguage interoperability.
The output of a compiled .NET executable is called an assembly. An assem-
bly is made up of MSIL code and metadata. This is the package that is
delivered to the end user, which is compiled a second time into native
machine language when the user starts the application. An assembly has a
.DLL extension, but is different from a traditional Windows DLL.
Intermediate Language (IL) is an optimized compiled code developed by
Microsoft that .NET’s “jitter” (JIT) uses to compile into native machine
code.
02 71465_CH01 11/30/01 10:13 AM Page 16
Microsoft
JIT COMPILER .net
VERIFIER
LOADER
Metadata
IL Code
XML
ASP.NET Web X
Service coded with
VB.NET and HTML Compiled
source code:
C# Class C++ C# Windows form intermediate
Libraries DCOM dll GUI Language (IL)
Figure 1.3: Compiling an assembly into native machine code for execution
within the Common Language Runtime.
What’s Next? 17
What’s Next?
In the next chapter, we will see how ASP.NET fits into the .NET architec-
ture, what some of its most exciting features are, and how it differs from
classic ASP. By the end of the chapter, if you’re currently building web sites
using ASP, you should be eager to make the jump to ASP.NET and start
taking advantage of all of the benefits it has over ASP.
03 71465_CH02 11/30/01 10:31 AM Page 18
03 71465_CH02 11/30/01 10:31 AM Page 19
2
An Introduction To ASP.NET
Microsoft Active Server Pages (ASP) technology has evolved once more.
This time, the changes Microsoft has made are so great that they have cho-
sen not to make another point release of ASP (to 4.0), but have labeled this
next generation of their Internet technology ASP.NET. ASP.NET (formerly
Next Generation Web Services or ASP+) and the .NET framework will
change the way developers build powerful Internet applications more than
any prior evolution of ASP before it. Although entire books could be written
about the .NET framework (and, as you read this, I’m sure they have been),
we can only cover some of the major points about this new architecture
before jumping into specific ASP.NET examples.
In this chapter you will
• Take a look at a brief history of Active Server Pages (ASP)
• Learn what ASP.NET is
• Compare the benefits ASP.NET with those of “Classic ASP”
03 71465_CH02 11/30/01 10:31 AM Page 20
Moving to .NET
What is .NET? .NET is Microsoft’s new programming architecture, and is
an effort to unify development so that true language independence can be
achieved. Further, .NET is designed for the disconnected Internet program-
ming model, rather than the traditional two-tier client/server model that
Distributed Component Object Model (DCOM) and other earlier models
supported. ASP.NET is just one piece of this new architecture, and of course
is the focus of this book.
What does ASP.NET do for you, the developer? Well, let’s look at a list of 15
cool new things about ASP.NET as compared to ASP 3.0. This comparison is
not meant to be complete, because this is just an introduction to ASP.NET,
but it should give you a good idea of why ASP.NET is far superior to its pre-
decessor. So, in no particular order, here are some of the major improve-
ments. Don’t worry if there are some items listed that are unclear—we will
cover each point in more detail before the end of the chapter.
• Compiled code, not interpreted
• Separation of code from content
• No more “DLL hell”
• Side-by-side installation
• Real debugging
• Real programming languages
• Real error handling
• Applications can be deployed with XCOPY or FTP
• Applications can be administered with XML-structured configuration
files
• Event-based programming model
• Improved object model
• More integrated functions, such as form validation and integral form
handling
• Web Services
• Great performance enhancements from features like page caching
• Better tools—Visual Studio .NET rules!
03 71465_CH02 11/30/01 10:31 AM Page 21
This chapter will provide a brief look at the background of ASP.NET and
how it has evolved from ASP. I’ll explain the key differences between ASP
3.0 and ASP.NET in an overview fashion, and issues such as migrating
from “classic ASP” to ASP.NET will be covered in later chapters.
First, if ASP had not been released with ActiveX Data Objects (ADO), it
most likely would not have gained in popularity as quickly as it did. ADO
replaced Remote Data Objects (RDO) and later Data Access Objects (DAO)
as Microsoft’s preferred method of accessing databases, and it provided a
simple, straightforward object model.
Second, with the release of ASP 1.0 came the first Microsoft Visual Studio
application suite, which includes Visual InterDev 1.0. This tool provided
many features, especially for a 1.0 product, and took advantage of
Microsoft’s FrontPage Server Extensions (FPSE) to allow easy maintenance
of Web sites without the need for a separate FTP client. Intellisense for
COM and built-in ASP objects as well as a data access control made this a
very popular editor despite its shortcomings, such as its Graphical User
Interface (GUI) editor, which relied on an early version of FrontPage.
It is probably safe to say that if it were not for ASP, the third-party compo-
nent market would not be the multimillion dollar per year industry that it
is today. Certainly this was not the only factor, as third-party controls for
Visual Basic predated the COM revolution, but in my opinion, ASP and
COM have allowed some businesses to become very profitable by selling
pre-packaged components for use on web servers. The ability to purchase
off-the-shelf components and plug them into a Web site simply did not exist
for all but the most skilled of programmers prior to the release of ASP 1.0.
By bringing this capability to the masses, ASP opened up an entirely new
market for component vendors, who continue to provide powerful off-the-
shelf tools that are easily integrated into ASP applications.
03 71465_CH02 11/30/01 10:31 AM Page 22
The fourth feature of ASP that sparked its popularity was its use of
VBScript as its default language. This allowed the many programmers who
were already familiar with Visual Basic to quickly jump into ASP program-
ming with minimal learning required. For the many programmers familiar
with JavaScript, or the syntactically similar C, JScript was offered as well.
In fact, Microsoft provided the ability to use other third-party languages as
well, and it wasn’t long before one could write ASP code in Perl.
As cool as it was, ASP 1.0 had some significant limitations. One major limi-
tation for anyone working with COM components was that the Web server
needed to be restarted whenever a Dynamic Link Library (DLL) needed to
be updated (A COM object is stored as a .DLL file). Other security and per-
formance issues were addressed, but the largest improvements from ASP
1.0 to 2.0 came in the form of Microsoft Transaction Server (MTS). ASP 2.0
shipped as part of Internet Information Server (IIS) 4.0 and MTS 1.0
shipped as part of the free Windows NT 4 Option Pack.
With IIS 4.0, Microsoft introduced the new Microsoft Management Console
(MMC), which was used to administer both IIS 4.0 and MTS. MTS made
life much easier for anyone developing or using COM components. It han-
dled installation and uninstallation of the components, alleviating the need
to restart the Web service (or often the server itself), and also removed a lot
of the burden of handling transactions from the developer. In addition, it
acted as an object broker, effectively caching object instances and brokering
them out on request. This technique led to the current focus on “stateless”
components because this was necessary for such object reuse to be effective.
In addition, newer versions of ADO further enhanced developers’ abilities to
work with remote data, using new techniques like XML streams, among
other things.
In February 2000, Microsoft released IIS 5.0 with Windows 2000. With IIS
5.0, ASP was in version 3.0, and MTS was replaced with COM+ services.
COM+ essentially combined the functionality of MTS with message queuing
services, and ASP gained some additional functionality, including a few
more methods and intrinsic object properties. On the whole, the major dif-
ferences between programming in ASP 2.0 and ASP 3.0 lay in the support-
ing services like COM+ more than in the language itself. Anyone who could
write VBScript in ASP 1.0 with Visual InterDev 1.0 would still be perfectly
at home using IIS 4.0 or IIS 5.0. This simply is not the case with ASP.NET.
Microsoft employees Mark Anders and Scott Guthrie began developing
what would become ASP.NET in early January of 1998. At this time, ASP
was just a year old, but some of its limitations were already quite evident.
03 71465_CH02 11/30/01 10:31 AM Page 23
For instance, the restriction to scripting languages and the lack of a compo-
nent model for ASP made it difficult to develop good tools for it. The inter-
spersing of code with output HyperText Markup Language (HTML)
frequently resulted in problems when designers and developers worked
together on the same project. ASP.NET was designed from the start to
address the limitations of ASP and overcome them.
Mark and Scott chose to build ASP.NET, then called ASP+, on the Next
Generation Web Services (NGWS) Runtime that was then in development.
NGWS, which would become .NET, provided a rich set of programming
libraries, and would soon include the new language C#, in which ASP.NET
itself is written. At this time, ASP.NET has been in development for over
three years, and Microsoft’s focus with this product remains on these
priorities:
• Factored design. ASP.NET is written as a set of modular compo-
nents that can be replaced or extended as needed.
• Scalability. Great efforts were made to build a highly scalable model,
especially with regard to maintaining state.
• Availability. ASP.NET has been designed to intelligently detect
crashes, memory leaks, and deadlocks and to recover from these
events gracefully.
• Performance. ASP.NET takes advantage of compiled languages and
early binding to improve performance, and also features extensive
caching support.
• Tools integration. Microsoft’s goal is to make building a Web site as
easy as building a form using Visual Basic. Visual Studio .NET is the
first tool to provide this functionality, but the other vendors are sure
to follow with their own toolsets.
the application, and the entire application can be moved using simple file
copying. No registry changes or dealing with MTS/COM+ is necessary! This
makes it very easy to maintain an ASP.NET application remotely, such as
through a Web hosting provider. Of course, components can still be shared,
but that decision is now left to the developer or administrator.
Side-by-Side Installation
If you’re not sure you’re ready to migrate your production applications to
ASP.NET yet, don’t worry. The new services and features can be installed
and running in parallel with your existing classic ASP applications (on IIS
4 or 5). In fact, they can share the same folder structure—all that you need
do to migrate each file (after you’ve made it utilize the new features of
ASP.NET) is change the file extension from .asp to .aspx (and of course
update your links to this file accordingly). You will literally be able to
migrate your applications a page at a time.
Real Debugging
ASP.NET features easier debugging than did Classic ASP (which isn’t say-
ing much). One simple addition is a trace command that is only compiled
into the running code when a compile flag is set. No need to build your own
debugging code using if-then and Response.Write. Also, with Visual Studio
.NET, you can step through your ASP.NET code, your include files and Web
controls, and your .NET components, even if each of these uses a different
programming language, without being on the server. It is real debugging,
just as with any other Visual tool!
Directory-Based Deployment
Migrating an ASP application from one server to another is a daunting
task. FrontPage extensions, COM components, and Web settings are all
separate from the actual files in the directory to be moved. With ASP.NET,
you can deploy your application, complete with server settings and compo-
nents, using XCOPY or FTP. This makes backing up a site much easier, and
eliminates a lot of the hassle involved with remote Web hosting.
Once, in the days of MS-DOS, programs were as easy to install, move, and
uninstall as directories were to copy. Moving the files moved the program.
With the advent of Windows and the notorious system registry, this simplic-
ity was lost. Now, with .NET, we can once again install entire applications
using nothing more than a file manager or FTP client.
ebookgate.com