ASP NET by Example 6th Edition Steven A. Smith 2024 scribd download
ASP NET by Example 6th Edition Steven A. Smith 2024 scribd download
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.
By Thomas Aird.
By Professor Wilson.
The coffin was let down to the bottom of the grave, the planks were
removed from the heaped-up brink, the first rattling clods had struck
their knell, the quick shovelling was over, and the long, broad,
skilfully cut pieces of turf were aptly joined together, and trimly laid
by the beating spade, so that the newest mound in the churchyard
was scarcely distinguishable from those that were grown over by the
undisturbed grass and daisies of a luxuriant spring. The burial was
soon over; and the party, with one consenting motion, having
uncovered their heads in decent reverence of the place and occasion,
were beginning to separate, and about to leave the churchyard. Here
some acquaintances, from distant parts of the parish, who had not
had an opportunity of addressing each other in the house that had
belonged to the deceased, nor in the course of the few hundred yards
that the little procession had to move over from his bed to his grave,
were shaking hands, quietly but cheerfully, and inquiring after the
welfare of each other’s families. There, a small knot of neighbours
were speaking, without exaggeration, of the respectable character
which the deceased had borne, and mentioning to one another little
incidents of his life, some of them so remote as to be known only to
the grayheaded persons of the group; while a few yards farther
removed from the spot, were standing together parties who
discussed ordinary concerns, altogether unconnected with the
funeral, such as the state of the markets, the promise of the season,
or change of tenants; but still with a sobriety of manner and voice
that was insensibly produced by the influence of the simple
ceremony now closed, by the quiet graves around, and the shadow of
the spire and gray walls of the house of God.
Two men yet stood together at the head of the grave, with
countenances of sincere but unimpassioned grief. They were
brothers, the only sons of him who had been buried. And there was
something in their situation that naturally kept the eyes of many
directed upon them for a longer time, and more intently, than would
have been the case had there been nothing more observable about
them than the common symptoms of a common sorrow. But these
two brothers, who were now standing at the head of their father’s
grave, had for some years been totally estranged from each other,
and the only words that had passed between them, during all that
time, had been uttered within a few days past, during the necessary
preparations for the old man’s funeral.
No deep and deadly quarrel was between these brothers, and
neither of them could distinctly tell the cause of this unnatural
estrangement. Perhaps dim jealousies of their father’s favour—selfish
thoughts that will sometimes force themselves into poor men’s
hearts respecting temporal expectations—unaccommodating
manners on both sides—taunting words that mean little when
uttered, but which rankle and fester in remembrance—imagined
opposition of interests, that, duly considered, would have been found
one and the same—these, and many other causes, slight when single,
but strong when rising up together in one baneful band, had
gradually but fatally infected their hearts, till at last they who in
youth had been seldom separate, and truly attached, now met at
market, and, miserable to say, at church, with dark and averted faces,
like different clansmen during a feud.
Surely if anything could have softened their hearts towards each
other, it must have been to stand silently, side by side, while the
earth, stones, and clods, were falling down upon their father’s coffin.
And, doubtless, their hearts were so softened. But pride, though it
cannot prevent the holy affections of nature from being felt, may
prevent them from being shown; and these two brothers stood there
together, determined not to let each other know the mutual
tenderness that, in spite of them, was gushing up in their hearts, and
teaching them the unconfessed folly and wickedness of their
causeless quarrel.
A headstone had been prepared, and a person came forward to
plant it. The elder brother directed him how to place it—a plain
stone, with a sand-glass, skull, and cross-bones, chiselled not rudely,
and a few words inscribed. The younger brother regarded the
operation with a troubled eye, and said, loudly enough to be heard by
several of the bystanders, “William, this was not kind in you;—you
should have told me of this. I loved my father as well as you could
love him. You were the elder, and, it may be, the favourite son; but I
had a right in nature to have joined you in ordering this headstone,
had I not?”
During these words, the stone was sinking into the earth, and
many persons who were on their way from the grave returned. For a
while the elder brother said nothing, for he had a consciousness in
his heart that he ought to have consulted his father’s son in designing
this last becoming mark of affection and respect to his memory; so
the stone was planted in silence, and now stood erect, decently and
simply among the other unostentatious memorials of the humble
dead.
The inscription merely gave the name and age of the deceased, and
told that the stone had been erected “by his affectionate sons.” The
sight of these words seemed to soften the displeasure of the angry
man, and he said, somewhat more mildly, “Yes, we were his
affectionate sons, and since my name is on the stone, I am satisfied,
brother. We have not drawn together kindly of late years, and
perhaps never may; but I acknowledge and respect your worth; and
here, before our own friends, and before the friends of our father,
with my foot above his head, I express my willingness to be on better
and other terms with you, and if we cannot command love in our
hearts, let us, at least, brother, bar out all unkindness.”
The minister, who had attended the funeral, and had something
intrusted to him to say publicly before he left the churchyard, now
came forward, and asked the elder brother why he spake not
regarding this matter. He saw that there was something of a cold and
sullen pride rising up in his heart—for not easily may any man hope
to dismiss from the chamber of his heart even the vilest guest, if once
cherished there. With a solemn and almost severe air, he looked
upon the relenting man, and then, changing his countenance into
serenity, said gently,—
Behold how good a thing it is,
And how becoming well,
Together such as brethren are
In unity to dwell.
On the morning of the 30th August 1695, just as the sun began to
tinge the dark and blood-stained battlements of Namur, a
detachment of Mackay’s Scottish regiment made their rounds,
relieving the last night-sentinels, and placing those of the morning.
As soon as the party returned to their quarters, and relaxed from the
formalities of military discipline, their leader, a tall, muscular man,
of about middle age, with a keen eye and manly features, though
swarthy and embrowned with toil, and wearing an expression but
little akin to the gentle or the amiable, moved to an angle of the
bastion, and, leaning on his spontoon, fixed an anxious gaze on the
rising sun. While he remained in this position, he was approached by
another officer, who, slapping him roughly on the shoulder, accosted
him in these words—
“What, Monteith! are you in a musing mood? Pray, let me have the
benefit of your morning meditations.”
“Sir!” said Monteith, turning hastily round. “Oh! ’tis you, Keppel.
What think you of this morning?”
“Why, that it will be a glorious day for some; and for you and me, I
hope, among others. Do you know that the Elector of Bavaria
purposes a general assault to-day?”
“I might guess as much, from the preparations going on. Well,
would it were to-morrow!”
“Sure you are not afraid, Monteith?”
“Afraid! It is not worth while to quarrel at present; but methinks
you, Keppel, might have spared that word. There are not many men
who might utter it and live.”
“Nay, I meant no offence; yet permit me to say, that your words
and manner are strangely at variance with your usual bearing on a
battle-morn.”
“Perhaps so,” replied Monteith; “and, but that your English
prejudices will refuse assent, it might be accounted for. That sun will
rise to-morrow with equal power and splendour, gilding this earth’s
murky vapours, but I shall not behold his glory.”
“Now, do tell me some soothful narrative of a second-sighted seer,”
said Keppel. “I promise to do my best to believe it. At any rate, I will
not laugh outright, I assure you.”
“I fear not that. It is no matter to excite mirth; and, in truth, I feel
at present strangely inclined to be communicative. Besides, I have a
request to make; and I may as well do something to induce you to
grant it.”
“That I readily will, if in my power,” replied Keppel. “So, proceed
with your story, if you please.”
“Listen attentively, then—and be at once my first and my last
confidant.
“Shortly after the battle of Bothwell Bridge, I joined the troop
commanded by Irvine of Bonshaw; and gloriously did we scour the
country, hunting the rebel Covenanters, and acting our pleasure
upon man, woman, and child, person and property. I was then but
young, and, for a time, rather witnessed than acted in the wild and
exciting commission which we so amply discharged. But use is all in
all. Ere half-a-dozen years had sped their round, I was one of the
prettiest men in the troop at everything. It was in the autumn of
1684, as I too well remember, that we were engaged in beating up the
haunts of the Covenanters on the skirts of Galloway and Ayrshire. A
deep mist, which covered the moors thick as a shroud—friendly at
times to the Whigs, but, in the present instance, their foe—concealed
our approach, till we were close upon a numerous conventicle. We
hailed, and bade them stand; but, trusting to their mosses and glens,
they scattered and fled. We pursued in various directions, pressing
hard upon the fugitives. In spite of several morasses which I had to
skirt, and difficult glens to thread, being well mounted, I gained
rapidly on a young mountaineer, who, finding escape by flight
impossible, bent his course to a house at a short distance, as hoping
for shelter there, like a hare to her form. I shouted to him to stand;
he ran on. Again I hailed him; but he heeded not; when, dreading to
lose all trace of him, should he gain the house, I fired. The bullet took
effect. He fell, and his heart’s blood gushed on his father’s threshold.
Just at that instant an aged woman, alarmed by the gallop of my
horse, and the report of the pistol, rushed to the door, and
stumbling, fell upon the body of her dying son. She raised his
drooping head upon her knee, kissed his bloody brow, and screamed
aloud, ‘Oh, God of the widow and the fatherless, have mercy on me!’
One ghastly convulsive shudder shook all her nerves, and the next
moment they were calm as the steel of my sword; then raising her
pale and shrivelled countenance, every feature of which was fixed in
the calm, unearthly earnestness of utter despair, or perfect
resignation, she addressed me, every word falling distinct and
piercing on my ear like dropping musketry.
“‘And hast thou this day made me a widowed, childless mother?
Hast thou shed the precious blood of this young servant of Jehovah?
And canst thou hope that thy lot will be one of unmingled happiness?
Go, red-handed persecutor! Follow thine evil way! But hear one
message of truth from a feeble and unworthy tongue. Remorse, like a
bloodhound, shall dog thy steps; and the serpent of an evil
conscience shall coil around thy heart. From this hour thou shalt
never know peace. Thou shalt seek death, and long to meet it as a
friend; but it shall flee thee. And when thou shalt begin to love life,
and dread death, then shall thine enemy come upon thee; and thou
shalt not escape. Hence to thy bloody comrades, thou second Cain!
Thou accursed and banished from the face of Heaven and of mercy!
—
“‘Foul hag!’ I exclaimed, it would take little to make me send thee
to join thy psalm-singing offspring!’
“‘Well do I know that thou wouldst if thou wert permitted!’ replied
she. ‘But go thy way, and bethink thee how thou wilt answer to thy
Creator for this morning’s work!’
“And, ceasing to regard me, she stooped her head over the dead
body of her son. I could endure no more, but wheeled around, and
galloped off to join my companions.
“From that hour, I felt myself a doomed and miserable man. In
vain did I attempt to banish from my mind the deed I had done, and
the words I had heard. In the midst of mirth and revelry, the dying
groan of the youth, and the words of doom spoken by his mother,
rung for ever in my ears, converting the festal board to a scene of
carnage and horror, till the very wine-cup seemed to foam over with
hot bubbling gore. Once I tried—laugh, if you will—I tried to pray;
but the clotted locks of the dying man, and the earnest gaze of the
soul-stricken mother, came betwixt me and Heaven,—my lip faltered
—my breath stopped—my very soul stood still, for I knew that my
victims were in Paradise, and how could I think of happiness—I,
their murderer—in one common home with them? Despair took
possession of my whole being. I rushed voluntarily to the centre of
every deadly peril, in hopes to find an end to my misery. Yourself can
bear me witness that I have ever been the first to meet, the last to
retire from, danger. Often, when I heard the battle-signal given, and
when I passed the trench, or stormed the breach, in front of my
troop, it was less to gain applause and promotion than to provoke the
encounter of death. ’Twas all in vain. I was doomed not to die, while I
longed for death. And now—”
“Well, by your own account, you run no manner of risk, and at the
same time are proceeding on a rapid career of military success,” said
Keppel; “and, for my life, I cannot see why that should affect you,
supposing it all perfectly true.”
“Because you have not yet heard the whole. But listen a few
minutes longer. During last winter, our division, as you know, was
quartered in Brussels, and was very kindly entertained by the
wealthy and good-natured Flemings. Utterly tired of the heartless
dissipation of life in a camp, I endeavoured to make myself agreeable
to my landlord, that I might obtain a more intimate admission into
his family circle. To this I was the more incited, that I expected some
pleasure in the society of his daughter. In all I succeeded to my wish.
I became quite a favourite with the old man, and procured ready
access to the company of his child. But I was sufficiently piqued to
find, that in spite of all my gallantry, I could not learn whether I had
made any impression upon the heart of the laughing Fanchon. What
peace and playful toying could not accomplish, war and sorrow did.
We were called out of winter quarters, to commence what was
anticipated to be a bloody campaign. I obtained an interview to take
a long and doubtful farewell. In my arms the weeping girl owned her
love, and pledged her hand, should I survive to return once more to
Brussels. Keppel, I am a doomed man; and my doom is about to be
accomplished! Formerly I wished to die; but death fled me. Now I
wish to live; and death will come upon me! I know I shall never more
see Brussels, nor my lovely little Fleming. Wilt thou carry her my last
farewell; and tell her to forget a man who was unworthy of her love—
whose destiny drove him to love, and be beloved, that he might
experience the worst of human wretchedness? You’ll do this for me,
Keppel?”
“If I myself survive, I will. But this is some delusion—some strong
dream. I trust it will not unnerve your arm in the moment of the
storm.”
“No! I may die—must die; but it shall be in front of my troop, or in
the middle of the breach. Yet how I long to escape this doom! I have
won enough of glory; I despise pillage and wealth; but I feel my very
heartstrings shrink from the now terrible idea of final dissolution.
Oh! that the fatal hour were past, or that I had still my former
eagerness to die! Keppel, if I dared, I would to-day own myself a
coward.”
“Come with me,” said Keppel, “to my quarters. The night air has
made you aguish. The cold fit will yield to a cup of as generous Rhine
wine as ever was drunk on the banks of the Sambre.” Monteith
consented, and the two moved off to partake of the stimulating and
substantial comforts of a soldier’s breakfast in the Netherlands.
It was between one and two in the afternoon. An unusual stillness
reigned in the lines of the besiegers. The garrison remained equally
silent, as watching in deep suspense on what point the storm
portended by this terrible calm would burst. A single piece of
artillery was discharged. Instantly a body of grenadiers rushed from
the intrenchments, struggled over masses of ruins, and mounted the
breach. The shock was dreadful. Man strove with man, and blow
succeeded to blow, with fierce and breathless energy. The English
reached the summit, but were almost immediately beaten back,
leaving numbers of their bravest grovelling among the blackened
fragments. Their leader, Lord Cutts, had himself received a
dangerous wound in the head; but disregarding it, he selected two
hundred men from Mackay’s regiment, and putting them under the
command of Lieutenants Cockle and Monteith, sent them to restore
the fortunes of the assault. Their charge was irresistible. Led on by
Monteith, who displayed a wild and frantic desperation, rather than
bravery, they broke through all impediments, drove the French from
the covered way, seized on one of the batteries, and turned the
cannon against the enemy. To enable them to maintain this
advantage, they were reinforced by parties from other divisions.
Keppel, advancing in one of those parties, discovered the mangled
form of his friend Monteith, lying on heaps of the enemy on the very
summit of the captured battery. He attempted to raise the seemingly
lifeless body. Monteith opened his eyes,—“Save me!” he cried; “save
me! I will not die! I dare not—I must not die!”
It were too horrid to specify the ghastly nature of the mortal
wounds which had torn and disfigured his frame. To live was
impossible. Yet Keppel strove to render him some assistance, were it
but to soothe his parting spirit. Again he opened his glazing eyes,—“I
will resist thee to the last!” he cried, in a raving delirium. “I killed
him but in the discharge of my duty. What worse was I than others?
Poor consolation now! The doom—the doom! I cannot—dare not—
must not—will not die!” And while the vain words were gurgling in
his throat, his head sunk back on the body of a slaughtered foe, and
his unwilling spirit forsook his shattered body.—Edinburgh Literary
Journal.
THE LADY OF WARISTOUN.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookgate.com