www.it-ebooks.info
Beginning ASP.NET 1.1
with Visual C#® .NET 2003
Chris Ullman
John Kauffman
Chris Hart
Dave Sussman
Daniel Maharry
Wiley Publishing, Inc.
www.it-ebooks.info
www.it-ebooks.info
Beginning ASP.NET 1.1
with Visual C#® .NET 2003
www.it-ebooks.info
www.it-ebooks.info
Beginning ASP.NET 1.1
with Visual C#® .NET 2003
Chris Ullman
John Kauffman
Chris Hart
Dave Sussman
Daniel Maharry
Wiley Publishing, Inc.
www.it-ebooks.info
Beginning ASP.NET 1.1 with Visual C#® .NET 2003
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2004 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
Library of Congress Card Number: 2004100135
ISBN: 0-7645-5708-4
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
1B/RW/RS/QU
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by
any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted
under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright
Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8700. Requests to
the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475
Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4447, Email:
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: WHILE THE PUBLISHER AND AUTHOR
HAVE USED THEIR BEST EFFORTS IN PREPARING THIS BOOK, THEY MAKE NO
REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS
OF THE CONTENTS OF THIS BOOK AND SPECIFICALLY DISCLAIM ANY IMPLIED WARRANTIES
OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE
CREATED OR EXTENDED BY SALES REPRESENTATIVES OR WRITTEN SALES MATERIALS. THE
ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR YOUR SITUATION.
YOU SHOULD CONSULT WITH A PROFESSIONAL WHERE APPROPRIATE. NEITHER THE
PUBLISHER NOR AUTHOR SHALL BE LIABLE FOR ANY LOSS OF PROFIT OR ANY OTHER
COMMERCIAL DAMAGES, INCLUDING BUT NOT LIMITED TO SPECIAL, INCIDENTAL,
CONSEQUENTIAL, OR OTHER DAMAGES.
For general information on our other products and services or to obtain technical support, please contact our
Customer Care Department within the U.S. at (800) 762-2974, outside the U.S. at (317) 572-3993 or fax (317)
572-4002.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not
be available in electronic books.
Trademarks: Wiley, the Wiley Publishing logo, Wrox, the Wrox logo, Programmer to Programmer, and
related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates in
the United States and other countries, and may not be used without written permission. All other
trademarks are the property of their respective owners. Wiley Publishing, Inc. is not associated with any
product or vendor mentioned in this book.
www.it-ebooks.info
About the Authors
Chris Ullman
Chris Ullman is a freelance Web developer and technical author who has spent many years stewing in
ASP/ASP.NET, like a teabag left too long in the pot. Coming from a Computer Science background, he
started initially as a UNIX/Linux guru, who gravitated towards MS technologies during the summer of
ASP (1997). He cut his teeth on Wrox Press ASP guides, and since then he has written over 20 books,
most notably as lead author for Wrox's bestselling Beginning ASP/ASP.NET series, and has contributed
chapters to books on PHP, ColdFusion, JavaScript, Web Services, C#, XML and other Internet-related
technologies too esoteric to mention, now swallowed up in the quicksands of the dot.com boom.
Quitting Wrox as a full-time employee in August 2001, he branched out into VB6 programming and ASP
development, maintaining a multitude of sites from , his "work" site, to
, a selection of his writings on music and art. He now divides his time
between being a human punchbag for his 29-month-old son Nye, composing electronic sounds on bits
of dilapidated old keyboards for his music project Open E, and tutoring his cats in the art of peaceful
co-existence, and not violently mugging each other on the stairs.
Chris Ullman contributed Chapters 1, 14, 15, 16, 17, and Appendix E to this book.
John Kauffman
John Kauffman was born in Philadelphia, the son of a chemist and a nurse. He received his degrees from
The Pennsylvania State University, the colleges of Science and Agriculture. His early research was for
Hershey foods in the genetics of the chocolate tree and the molecular biology of chocolate production.
Subsequently, he moved to the Rockefeller University, where he cloned and sequenced DNA regions that
control the day and night cycles of plants.
Since 1997, John has written ten books, six of which have been on the Amazon Computer Best Seller
List. His specialty is programming Web front-ends for enterprise-level databases.
In his spare time, John is an avid sailor and youth sailing coach. He represented the USA in the sailing
World Championship of 1985 and assisted the Olympic teams of Belgium and China in 1996. He also
enjoys jazz music and drumming and manages to read the New Yorker from cover-to-cover each week.
My portions of this book are dedicated to the instructors of two drum and bugle corps. These men
taught me about precision, accuracy, and discipline: Ken Green and John Flowers of the Belvederes 1976
and Dennis DeLucia and Bobby Hoffman of the Bayonne Bridgemen 1978.
John Kauffman contributed Chapters 2, 3, 4, 5, 6, and Appendix B to this book.
www.it-ebooks.info
Chris Hart
Chris Hart is a full-time .NET Developer and part-time author who lives in Birmingham (UK) with her
husband James. While she's most at home in the world of the Web, she's recently been working with the
.NET Compact Framework. In her spare time, Chris spends much of her time playing with beta
technologies, and then attempting to write about them.
Chris has contributed many chapters to a variety of books, including Beginning ASP.NET (Wrox Press),
Beginning Dynamic Websites with ASP.NET Web Matrix (Wrox Press), and most recently, A Programmer's
Guide to SQL (Apress).
When she gets away from computers, Chris enjoys travel, especially when it involves driving along
narrow winding roads to get to out-of-the-way parts of Scotland. She dreams of building her own house
somewhere where she can keep a cat.
Chris Hart contributed Chapters 10, 11, 12, 13, and Appendices C and D to this book.
Dave Sussman
Dave Sussman is a writer, trainer, and consultant, living in the wilds of the Oxfordshire countryside.
He's been working with ASP.NET since before it was first released and still isn't bored with it. You can
contact him at
Dave Sussman contributed Chapters 7, 8, and 9 to this book.
Daniel Maharry
Dan Maharry is a freelance writer, reviewer, speaker, and editor who has, in no particular order, taught
English, Math, and Guitar, directed, crewed, acted in, and produced several plays and short films, been a
film and music columnist for four years, co-founded ASPToday.com, rewritten his own at HMobius.com
several times, opened an office in India, variously edited, reviewed, and written pieces of over 40
programming books, qualified as a sound engineer, and consumed enough caffeine in his lifetime to
keep most of China awake for a week. Occasionally, he sleeps. Sometimes. Contact him at
"With deep-felt love to Jane, and in memoriam to John Kauffman's father."
Dan Maharry contributed Chapters 5 and 6 to this book.
www.it-ebooks.info
Credits
Authors
Executive Editorial Director
Chris Ullman
John Kauffman
Chris Hart
Dave Sussman
Daniel Maharry
Mary Bednarek
Project Coordinator
Mary Richards
Project Manager
Senior Acquisitions Editor
Ami Frank Sullivan
Jim Minatel
Senior Production Manager
Vice President & Executive Group
Publisher
Fred Bernardi
Richard Swadley
Editorial Manager
Mary Beth Wakefield
Vice President and Executive Publisher
Bob Ipsen
Book Producer
Peer Technical Services Pvt. Ltd.
Vice President and Publisher
Joseph B. Wikert
www.it-ebooks.info
www.it-ebooks.info
Contents
Introduction
xxi
Chapter 1: Getting Started with ASP.NET
What Is a Static Web Page?
How Are Static Web Pages Served?
1
2
3
Limitations of Static Web Pages
What Is a Web Server?
4
5
How Are Dynamic Web Pages Served?
6
Client-Side Dynamic Web Pages
Server-Side Dynamic Web Pages
6
7
What Is ASP.NET?
9
How Does ASP.NET Differ from ASP?
Using C# with ASP.NET
I'm Still Confused about ASP, ASP.NET, and C#
The Installation Process
9
10
11
11
Which Operating System Do You Have?
Prerequisites for Installing ASP.NET
Try It Out Installing MDAC 2.8
Installing ASP.NET and the .NET Framework
Try It Out Installing the .NET Framework Redistributable
Installing Web Matrix
11
12
13
13
14
15
Try It Out Installing Web Matrix
Configuring Web Matrix to Run with .NET Framework 1.1
Try It Out Configuring Web Matrix
Running Web Matrix and Setting Up the Web Server
Try It Out Starting the Web Server
ASP.NET Test Example
16
18
18
19
19
25
Try It Out Your First ASP.NET Web Page
ASP.NET Troubleshooting
25
28
Page Cannot Be Displayed: HTTP Error 403
Page Cannot Be Found: HTTP Error 404
Web Page Unavailable While Offline
I Just Get a Blank Page
The Page Displays the Message But Not the Time
I Get an Error Statement Citing a Server Error
I Have a Different Problem
Summary
29
30
31
31
31
32
33
33
www.it-ebooks.info
Contents
Chapter 2: Anatomy of an ASP.NET Page
What Is .NET?
35
35
From Your Code to Machine Code
Introducing Two Intermediate Languages
Objects
The .NET Base Classes
The Class Browser
37
37
38
39
40
How ASP.NET Works
41
Saving Your ASP.NET Files with an ASPX Suffix
Inserting ASP.NET Code into Our Web Pages
Try It Out Inserting Server-Side (ASP.NET) Code
Try It Out Interweaving ASP.NET Output with HTML
ASP.NET in Action
42
42
44
49
51
Binding to a Database
51
Try It Out Binding to a Database
51
Binding to a Simple XML File
54
Try It Out Binding to a Simple XML Document
Summary
Exercises
54
57
58
Chapter 3: Server Controls and Variables
59
Forms
Web Pages, HTML Forms, and Web Forms
Request and Response in Non-ASP.NET Pages
60
60
61
Where ASP.NET Fits in with the .NET Framework
The <form> Tag in ASP.NET
63
64
Using ASP.NET Server Controls
64
<asp:Label>
65
Try It Out Using the <asp:Label> Control
Modifying ASP.NET Controls
<asp:DropDownList>
67
68
69
Try It Out Using the <asp:DropDownList> Control
<asp:ListBox>
69
73
Try It Out Using the <asp:ListBox> Control
<asp:TextBox>
73
75
Try It Out Using the <asp:TextBox> Control
<asp:RadioButtonList> and <asp:RadioButton>
Try It Out Using the <asp:RadioButtonList> Control
<asp:CheckBox> and <asp:CheckBoxList>
Try It Out Using the <asp:CheckBox> Control
75
77
78
79
80
Storing Information in C# Variables
82
Declaring Value Type Variables
82
Try It Out Using Variables
83
Datatypes
86
Numeric
Text Datatypes
Other Datatypes
Naming Variables
86
88
89
90
x
www.it-ebooks.info
Contents
Variable Scope
91
Try It Out Creating Block and Function-Level Variables
Constants
Conversion Functions
Arrays
92
97
97
98
Try It Out Using Arrays
99
Data Collections
103
ArrayList
103
Try It Out Using an ArrayList
Hashtables
105
106
Try It Out Using Hashtables
SortedList
108
110
Summary
Exercises
111
112
Chapter 4: Control Structures and Procedural Programming
Operators
113
113
Assignment Operator
Arithmetic Operators
114
114
Try It Out Tax Calculator Using Arithmetic Operators
String Concatenation
Numeric Comparison Operators
Logical Operators
Try It Out Tax Calculator Using Logical Operators
Control Structures
115
118
119
120
122
125
Overview of Branching Structures
Overview of Looping Structures
Overview of Jumping Structures
Uses of Control Structures
125
126
126
127
Branching Structures
128
The if Structure
129
Try It Out Using the if Structure
The switch Structure
134
138
Try It Out Using the switch Structure
Looping Structures
141
144
The for Loop Structure
144
Try It Out Using the for Loop
The while Loop
146
148
Try It Out Using the while Loop
The do...while Structure
150
151
Try It Out Using do...while
The foreach...in Loop
152
155
Summary
Exercises
156
157
Chapter 5: Functions
159
Overview
Modularization
159
160
xi
www.it-ebooks.info
Contents
Defining and Using Functions
161
Try It Out Defining and Using a Simple Function
Passing Parameters to Functions
161
164
Try It Out Functions with Parameters
Web Controls as Parameters
165
169
Try It Out Using Web Controls as Parameters
Return Values
170
173
Using Return Values in Your Code
173
Try It Out Handling Function Return Types
Value, Reference, and Out Parameters
175
181
Try It Out Using Value, Reference, and Out Parameters
Modularization Best Practices
Summary
Exercises
183
188
189
190
Chapter 6: Event-Driven Programming and Postback
What Is an Event?
What Is Event-Driven Programming?
HTML Events
ASP.NET's Trace Feature
ASP.NET Page Events
ASP.NET Web Control Events
191
192
192
193
195
197
199
Try It Out Creating Event Handlers with Web Matrix
Event-Driven Programming and Postback
Try It Out Reacting to Events in HTML and ASP.NET
The IsPostBack Test
201
202
203
205
Try It Out Calculator
206
Summary
Exercises
211
212
Chapter 7: Objects
215
Classes and Instances
Properties, Methods, and Events
Objects in .NET
Why Use Objects?
Defining Classes
216
216
216
217
218
Try It Out Creating a Class
218
Property Variables
Property Types
223
224
Try It Out Read-Only Properties
224
Initializing Objects
226
Try It Out Overloading a Constructor
Implementing Methods
226
227
Try It Out Adding Methods to a Class
Consolidating Overloaded Methods
227
230
Advanced Classes
231
xii
www.it-ebooks.info
Contents
Shared or Static Properties and Methods
Inheritance
Try It Out Inheritance
231
232
233
Interfaces
237
Try It Out Creating an Interface
.NET Objects
238
243
Namespaces
The Class Browser
243
243
Summary
Exercises
245
245
Chapter 8: Reading from Databases
Understanding Databases
247
247
Tables
Normalization
SQL and Stored Procedures
248
249
251
The Web Matrix Data Explorer
251
Try It Out Connecting to a Database
Creating Data Pages
251
253
Displaying Data Using the Data Explorer
Try It Out Creating a Grid
Displaying Data Using the Web Matrix Template Pages
Try It Out Creating a Data Page
Displaying Data Using the Code Wizards
Try It Out Creating a Data Page
ADO.NET
253
253
256
257
262
262
269
The OleDbConnection Object
The OleDbCommand Object
271
271
Try It Out Using Parameters
The OleDataAdapter Object
The DataSet Object
The DataReader Object
273
278
278
278
Try It Out Using a DataReader
Summary
Exercises
279
281
281
Chapter 9: Advanced Data Handling
More Data Objects
283
283
The DataTable Object
The DataRow Object
284
285
Try It Out The DataTable and DataRow Objects
Updating Databases
286
288
ADO.NET versus ADO
Updating Data in a DataSet
289
289
Try It Out Adding, Editing, and Deleting Rows
Updating the Original Data Source
Try It Out Auto-Generated Commands
Updating the Database
289
297
298
301
xiii
www.it-ebooks.info
Contents
Try It Out Updating the Database
302
Updating Databases Using a Command
307
Try It Out Executing Commands Directly
Summary
Exercises
307
310
311
Chapter 10: ASP.NET Server Controls
313
The Wrox United Application
ASP.NET Web Controls
HTML Server Controls
HTML Server Controls versus Web Controls
Web Controls
Rich Object Model
Automatic Browser Detection
Properties
314
315
316
318
319
320
320
320
Events
322
Try It Out Creating an Event Handler
Page Lifecycle
322
324
Page_Load()
Event Handling
Page_Unload()
325
326
326
Understanding Web Controls: The Wrox United Application
Try It Out Wrox United Main Page – Default.aspx
Intrinsic Controls
327
328
331
Try It Out Wrox United – Teams.aspx
Data Rendering Controls
332
340
Try It Out Wrox United – Teams.aspx, Part 2
Rich Controls
343
352
Try It Out Wrox United – Default.aspx, Part 2, the Event Calendar
Try It Out Wrox United – Displaying Fixture Details
Web Matrix Controls
354
360
366
Try It Out Wrox United – Players.aspx and the Web Matrix MX DataGrid
Validation Controls
367
372
Try It Out Wrox United – Registering for Email Updates (Default.aspx)
Summary
Exercises
373
378
378
Chapter 11: Users and Applications
381
Remembering Information in a Web Application
Cookies
382
383
Try It Out Using Cookies
386
Sessions
393
Try It Out Using Session State
395
Applications
404
How Do Applications Work?
405
Try It Out Using Application State
405
Reacting to Application and Session Events
Global.asax
410
410
xiv
www.it-ebooks.info
Contents
Try it Out Global.asax – Global Settings
Caching
411
413
Try It Out Wrox United – Caching Objects
State Management Recommendations
When to Use Cookies
When to Use Sessions
When to Use Applications
When to Use Caching
Other State Management Techniques
Using Multiple State Management Techniques on a Page
Try it Out Wrox United – Adding Some Style!
Summary
Exercises
415
418
419
419
419
419
420
421
421
429
430
Chapter 12: Reusable Code for ASP.NET
Encapsulation
Components
431
431
432
Why Use Components?
Applying Component Theory to Applications
User Controls
434
434
435
Try It Out Our First User Control
Try It Out Wrox United – Header Control
Try It Out Wrox United – Navigation User Control
Code-Behind
437
440
446
451
Try It Out Our First Code-Behind File
Try It Out Using Code-Behind in Wrox United
Summary
Exercises
452
457
459
459
Chapter 13: .NET Assemblies and Custom Controls
Three-Tier Application Design
ASP.NET Application Design
.NET Assemblies
463
464
465
466
Try It Out Our First ASP.NET Component
What Is Compilation?
467
470
Try It Out Compiling Our First ASP.NET Component
Accessing a Component from within an ASP.NET Page
Try It Out Using a Compiled Component
XCopy Deployment
Accessing Assemblies in Other Locations
Writing Code in Other Languages
Try It Out Writing a Component in VB.NET
Data Access Components
470
474
474
476
477
477
478
482
Try It Out Encapsulating Data Access Code in a Component
Custom Server Controls
482
489
What Are Custom Controls?
490
Try It Out Our First ASP.NET Custom Control
Composite Custom Controls
491
499
xv
www.it-ebooks.info
Contents
Try It Out Wrox United – Custom Composite Control
Summary
Exercises
499
506
507
Chapter 14: Debugging and Error Handling
A Few Good Habits
Tips on Coding
509
510
510
Indent Your Code
Structure Your Code
Comment Your Code
Convert Variables to the Correct Data Types (Validation)
Try to Break Your Code
Sources of Errors
511
511
512
512
513
514
Syntax Errors
514
Try It Out Syntax Error
Try It Out Generate a Compiler Error
Logical (Runtime) Errors
515
516
518
Try It Out Generate a Runtime Error
Try It Out Catching Illegal Values
Try It Out Using RequiredFieldValidator
System Errors
519
521
524
525
Finding Errors
525
Try It Out Viewing the Call-Stack
526
Debug Mode
527
Try It Out Disable the Debug Mode
Tracing
527
529
Try It Out Enabling Trace at the Page Level
Try It Out Writing to the Trace Log
Handling Errors
529
532
535
Try It Out Using try...catch...finally
Try It Out Using Page_Error()
Error Notification and Logging
542
548
550
Try It Out Creating Error Pages
551
Writing to the Event Log
553
Try It Out Writing to the Windows Error Log
Mailing the Site Administrator
554
557
Summary
Exercises
559
559
Chapter 15: Configuration and Optimization
Configuration Overview
561
562
Browsing .config Files
The Configuration Files
The Structure of the Configuration Files
562
564
567
Performance Optimization
574
Caching
574
Try It Out Output Caching
576
The Cache Object
578
xvi
www.it-ebooks.info
Contents
Expiring Information in the Cache
Try It Out Creating a File Dependency
Try It Out Creating a Key Dependency
Tips and Tricks
Summary
Exercises
581
582
586
590
591
591
Chapter 16: Web Services
593
What Is a Web Service?
594
Try It Out Creating Our First Web Service
HTTP, XML, and Web Services
595
598
HTTP GET
HTTP POST
599
600
Simple Object Access Protocol (SOAP)
Building an ASP.NET Web Service
Processing Directive
Namespaces
Public Class
Web Methods
601
603
603
603
604
604
Try It Out Creating a Web Service with Multiple Web Methods
Testing Your Web Service
605
607
Try It Out Conversions Test Page
Using Your Web Service
607
608
Try It Out Viewing the WSDL Contract
Try It Out ISBN Search Web Service
609
610
Consuming a Web Service
613
How Does a Proxy Work?
Creating a Proxy
613
615
Try It Out Accessing the ISBN Web Service from an ASP.NET Page
Creating a Web Service for the Wrox United Application
Try It Out Adding a Results Page
Try It Out Creating the Web Service
Web Service Discovery
Securing a Web Service
615
618
619
621
626
627
Username-Password Combination or Registration Keys
Try It Out Securing a Web Service with Username and Password
Secure Sockets Layer (SSL)
IP Address Restriction
Web Services Enhancements (WSE)
627
627
630
630
631
Other Web Services Considerations
631
Network Connectivity
Asynchronous Method Calls
Service Hijacking (or Piggybacking)
Provider Solvency
The Interdependency Scenario
631
631
632
633
633
Summary
Exercises
633
634
xvii
www.it-ebooks.info
Contents
Chapter 17: ASP.NET Security
635
What Is Security?
The ASP.NET Security Model
Authentication
636
636
637
Implementing Forms-Based Authentication
Try It Out Forms-Based Authentication
Forms-Based Authentication Using a Database
Try It Out Authenticating against a Database
Authorization
638
639
646
646
650
Try It Out Authorization for
Authentication in Wrox United
651
653
Try It Out Adding a Login Page to WroxUnited
Encryption Using SSL
653
664
Try It Out Enabling SSL
665
Summary
Exercises
666
666
Appendix A: Exercise Solutions
667
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Chapter 11
Chapter 12
Chapter 13
Chapter 14
Chapter 15
Chapter 16
Chapter 17
667
669
672
675
678
681
684
686
688
693
697
702
708
713
715
720
Appendix B: Web Matrix Quick Start
725
What Is Web Matrix?
Starting ASP.NET Web Matrix
725
727
The Screen
How to Enter Code
727
730
Try It Out Code Entry
731
Saving and Viewing Pages
731
Try It Out Formatting Modes, Views, and Serving Pages
Reusing Code
733
735
Try It Out Saving and Using Snippets
xviii
www.it-ebooks.info
735
Contents
Class Browser
735
Try It Out Class Browser Property Look-Up
What to Study Next
Summary
736
738
738
Appendix C: The Wrox United Database
741
The Database Design
741
Players
Status
Teams
PlayerTeams
Positions
Games
GameTypes
Locations
Opponents
Fans
742
742
743
743
744
744
745
745
746
746
Installing the Database
747
Installing the Access Database
Installing the MSDE Database
Appendix D: Web Application Development Using Visual Studio .NET
Creating a Web Application Project
Features of the Visual Studio .NET Environment
Visual Studio .NET Solutions and Projects
Files in a Web Application Project
Working with Web Pages
Compiling and Running Pages
Adding Code to the Code-Behind Class
Features of Code View
Adding Code to Methods
Styling Controls and Pages in Visual Studio .NET
Working in HTML View
Creating User Controls
Formatting Blocks of Code
Developing the User Control
Creating an XML File
Adding a User Control to a Page
Adding Custom Classes
Working with Databases Using the Server Explorer
Debugging in Visual Studio .NET
Using Breakpoints
Fixing Design-Time Errors
747
747
753
754
755
756
757
757
761
762
763
763
769
776
777
782
784
786
789
791
794
797
798
799
Suggested Exercises and Further Reading
801
xix
www.it-ebooks.info
Contents
Appendix E: Installing and Configuring IIS
Try It Out Locating and Installing IIS on Your Web Server Machine
Working with IIS
803
803
806
The Microsoft Management Console (MMC)
Testing Your Installation
Identifying Your Web Server's Name
Managing Directories on Your Web Server
Try It Out Creating a Virtual Directory and Setting Up Permissions
Permissions
806
807
807
808
810
814
Browsing to a Page on Your Web Server
818
Index
825
xx
www.it-ebooks.info
Introduction
ASP.NET is a radical update of Microsoft's Active Server Pages (ASP). ASP.NET is a powerful server based
technology designed to create dynamic and interactive HTML pages on demand for your Web site or
corporate intranet. Its design improves upon nearly every feature of classic ASP, from reducing the
amount of code you need to write to giving you more power and flexibility.
ASP.NET is a key element in Microsoft's .NET Framework, providing Web-based access to the
immensely powerful .NET development environment. It allows us to create Web applications in a new,
flexible way by placing commonly used code into reusable controls of various kinds that can fire events
initiated by the users of a site.
ASP.NET branches out into many other technologies, such as Web services, ADO.NET, custom controls,
and security. We will briefly touch upon its relationship with these fields throughout the book to provide
a solid, comprehensive understanding of how ASP.NET can benefit your work in a practical way.
ASP.NET 1.1 itself is a fairly light update to the complete wholesale changes that occurred in ASP.NET
1.0. This book by and large covers features that are available in both 1.0 and 1.1, but it covers the
pertinent new features of 1.1 in additional depth, which will be of interest to both the novice and
experienced users. So if you are already running ASP.NET 1.0, you will be expected to upgrade to 1.1.
By the end of this book you will be familiar with the anatomy of ASP.NET 1.1 and be able to create
powerful, secure, and robust Web sites that can collect and work with information in a multitude of
ways to the benefit of both you and your users.
Who Is This Book For?
The purpose of this book is to teach you from scratch how to use ASP.NET to write Web pages and Web
applications in which content can be programmatically tailored each time an individual client browser
calls them up. This not only saves you a lot of effort in presenting and updating your Web pages, but
also offers tremendous scope for adding sophisticated functionality to your site. As ASP.NET is not a
programming language in its own right, but rather a technology (as we shall explain in the book), we
will be teaching some basic programming principles in Chapters 2 to 7 in C#, our chosen language for
implementing ASP.NET.
This book is therefore ideal for somebody who knows some basic HTML but has never programmed
before, or somebody who is familiar with the basics of old style ASP, but hasn't investigated ASP.NET in
any detail. If you are an experienced programmer looking for a quick crash course on ASP.NET, or
somebody who's worked extensively with ASP, we suggest that you refer to Professional ASP.NET 1.1
Special Edition, Wiley ISBN: 0-7645-58900 instead, as you'll most likely find that the early chapters here
just reiterate things you already know. If are not familiar with HTML, then we suggest that you master
the basics of building Web pages before moving on to learning ASP.NET.
www.it-ebooks.info
Introduction
What Does This Book Cover?
This book teaches everything the novice user needs to know, from installing ASP.NET and the relevant
bits and pieces to creating pages and putting together the concepts to create a whole application using
ASP.NET 1.1.
Although ASP.NET 1.1 isn't a huge update on version 1.0, this book has been considerably overhauled
since edition 1.0. Plenty of the old chapters have been removed and many new ones introduced. We've
removed three chapters because we wanted to simplify the experience of learning ASP.NET. We've
created a brand new case study – an amateur sports league Web site – which is then used throughout
the latter chapters in the book to provide a more practical guide on how to implement ASP.NET
applications.
If you see the previous edition, you will find this one to be more cohesive, aimed towards the complete
novice and the developer with some ASP experience, and written with the benefit of hindsight from
experienced developers who have have been employed in creating ASP.NET applications. We trust that
you will find it a great improvement over the last, just as every new edition should be.
In the course of this book you will learn:
❑
What is ASP.NET
❑
How to install ASP.NET and get it up and running
❑
The structure of ASP.NET and how it sits on the .NET Framework
❑
How to use ASP.NET to produce dynamic, flexible, interactive Web pages
❑
Basic programming principles such as variables, controls structures, procedural programming,
and objects
❑
How to use ASP.NET to interface with different data sources, from databases to XML
documents
❑
What ready-made controls ASP.NET offers for common situations
❑
How to create your own controls
❑
How to debug your ASP.NET pages
❑
How to deal with unexpected events and inputs
❑
How to create your own Web application
❑
How to integrate your applications with Web services and how to create your own
❑
Some simple security features and how to create a login for an application
How This Book Is Structured
Here is a quick breakdown of what you will find in this book:
❑
Chapter 1 – Getting Started with ASP.NET: In the first chapter, we introduce ASP.NET and look
at some of the reasons that you'd want to use server-side code for creating Web pages as well as
the technologies that are available to do so. This done, we spend the bulk of the chapter
xxii
www.it-ebooks.info