Tải bản đầy đủ (.pdf) (90 trang)

Beginning ASP.NET 1.1 with Visual C# .NET 2003 phần 1 pptx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.68 MB, 90 trang )

Beginning ASP.NET 1.1
with Visual C#
®
.NET 2003
Chris Ullman
John Kauffman
Chris Hart
Dave Sussman
Daniel Maharry
Wiley Publishing, Inc.

Beginning ASP.NET 1.1
with Visual C#
®
.NET 2003

Beginning ASP.NET 1.1
with Visual C#
®
.NET 2003
Chris Ullman
John Kauffman
Chris Hart
Dave Sussman
Daniel Maharry
Wiley Publishing, Inc.
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 permis-
sion 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:

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.
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.
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.
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.
Authors
Chris Ullman
John Kauffman
Chris Hart
Dave Sussman
Daniel Maharry
Senior Acquisitions Editor
Jim Minatel
Vice President & Executive Group
Publisher
Richard Swadley
Vice President and Executive Publisher
Bob Ipsen
Vice President and Publisher
Joseph B. Wikert
Executive Editorial Director
Mary Bednarek
Project Coordinator
Mary Richards
Project Manager
Ami Frank Sullivan
Senior Production Manager

Fred Bernardi
Editorial Manager
Mary Beth Wakefield
Book Producer
Peer Technical Services Pvt. Ltd.
Credits
Contents
Introduction xxi
Chapter 1: Getting Started with ASP.NET 1
What Is a Static Web Page? 2
How Are Static Web Pages Served? 3
Limitations of Static Web Pages 4
What Is a Web Server? 5
How Are Dynamic Web Pages Served? 6
Client-Side Dynamic Web Pages 6
Server-Side Dynamic Web Pages 7
What Is ASP.NET? 9
How Does ASP.NET Differ from ASP? 9
Using C# with ASP.NET 10
I'm Still Confused about ASP, ASP.NET, and C# 11
The Installation Process 11
Which Operating System Do You Have? 11
Prerequisites for Installing ASP.NET 12
Try It Out Installing MDAC 2.8 13
Installing ASP.NET and the .NET Framework 13
Try It Out Installing the .NET Framework Redistributable 14
Installing Web Matrix 15
Try It Out Installing Web Matrix 16
Configuring Web Matrix to Run with .NET Framework 1.1 18

Try It Out Configuring Web Matrix 18
Running Web Matrix and Setting Up the Web Server 19
Try It Out Starting the Web Server 19
ASP.NET Test Example 25
Try It Out Your First ASP.NET Web Page 25
ASP.NET Troubleshooting 28
Page Cannot Be Displayed: HTTP Error 403 29
Page Cannot Be Found: HTTP Error 404 30
Web Page Unavailable While Offline 31
I Just Get a Blank Page 31
The Page Displays the Message But Not the Time 31
I Get an Error Statement Citing a Server Error 32
I Have a Different Problem 33
Summary 33
x
Contents
Chapter 2: Anatomy of an ASP.NET Page 35
What Is .NET? 35
From Your Code to Machine Code 37
Introducing Two Intermediate Languages 37
Objects 38
The .NET Base Classes 39
The Class Browser 40
How ASP.NET Works 41
Saving Your ASP.NET Files with an ASPX Suffix 42
Inserting ASP.NET Code into Our Web Pages 42
Try It Out Inserting Server-Side (ASP.NET) Code 44
Try It Out Interweaving ASP.NET Output with HTML 49
ASP.NET in Action 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 54
Summary 57
Exercises 58
Chapter 3: Server Controls and Variables 59
Forms 60
Web Pages, HTML Forms, and Web Forms 60
Request and Response in Non-ASP.NET Pages 61
Where ASP.NET Fits in with the .NET Framework 63
The <form> Tag in ASP.NET 64
Using ASP.NET Server Controls 64
<asp:Label> 65
Try It Out Using the <asp:Label> Control 67
Modifying ASP.NET Controls 68
<asp:DropDownList> 69
Try It Out Using the <asp:DropDownList> Control 69
<asp:ListBox> 73
Try It Out Using the <asp:ListBox> Control 73
<asp:TextBox> 75
Try It Out Using the <asp:TextBox> Control 75
<asp:RadioButtonList> and <asp:RadioButton> 77
Try It Out Using the <asp:RadioButtonList> Control 78
<asp:CheckBox> and <asp:CheckBoxList> 79
Try It Out Using the <asp:CheckBox> Control 80
Storing Information in C# Variables 82
Declaring Value Type Variables 82
Try It Out Using Variables 83
Datatypes 86
Numeric 86

Text Datatypes 88
Other Datatypes 89
Naming Variables 90
xi
Contents
Variable Scope 91
Try It Out Creating Block and Function-Level Variables 92
Constants 97
Conversion Functions 97
Arrays 98
Try It Out Using Arrays 99
Data Collections 103
ArrayList 103
Try It Out Using an ArrayList 105
Hashtables 106
Try It Out Using Hashtables 108
SortedList 110
Summary 111
Exercises 112
Chapter 4: Control Structures and Procedural Programming 113
Operators 113
Assignment Operator 114
Arithmetic Operators 114
Try It Out Tax Calculator Using Arithmetic Operators 115
String Concatenation 118
Numeric Comparison Operators 119
Logical Operators 120
Try It Out Tax Calculator Using Logical Operators 122
Control Structures 125
Overview of Branching Structures 125

Overview of Looping Structures 126
Overview of Jumping Structures 126
Uses of Control Structures 127
Branching Structures 128
The if Structure 129
Try It Out Using the if Structure 134
The switch Structure 138
Try It Out Using the switch Structure 141
Looping Structures 144
The for Loop Structure 144
Try It Out Using the for Loop 146
The while Loop 148
Try It Out Using the while Loop 150
The do while Structure 151
Try It Out Using do while 152
The foreach in Loop 155
Summary 156
Exercises 157
Chapter 5: Functions 159
Overview 159
Modularization 160
xii
Contents
Defining and Using Functions 161
Try It Out Defining and Using a Simple Function 161
Passing Parameters to Functions 164
Try It Out Functions with Parameters 165
Web Controls as Parameters 169
Try It Out Using Web Controls as Parameters 170
Return Values 173

Using Return Values in Your Code 173
Try It Out Handling Function Return Types 175
Value, Reference, and Out Parameters 181
Try It Out Using Value, Reference, and Out Parameters 183
Modularization Best Practices 188
Summary 189
Exercises 190
Chapter 6: Event-Driven Programming and Postback 191
What Is an Event? 192
What Is Event-Driven Programming? 192
HTML Events 193
ASP.NET's Trace Feature 195
ASP.NET Page Events 197
ASP.NET Web Control Events 199
Try It Out Creating Event Handlers with Web Matrix 201
Event-Driven Programming and Postback 202
Try It Out Reacting to Events in HTML and ASP.NET 203
The IsPostBack Test 205
Try It Out Calculator 206
Summary 211
Exercises 212
Chapter 7: Objects 215
Classes and Instances 216
Properties, Methods, and Events 216
Objects in .NET 216
Why Use Objects? 217
Defining Classes 218
Try It Out Creating a Class 218
Property Variables 223
Property Types 224

Try It Out Read-Only Properties 224
Initializing Objects 226
Try It Out Overloading a Constructor 226
Implementing Methods 227
Try It Out Adding Methods to a Class 227
Consolidating Overloaded Methods 230
Advanced Classes 231
xiii
Contents
Shared or Static Properties and Methods 231
Inheritance 232
Try It Out Inheritance 233
Interfaces 237
Try It Out Creating an Interface 238
.NET Objects 243
Namespaces 243
The Class Browser 243
Summary 245
Exercises 245
Chapter 8: Reading from Databases 247
Understanding Databases 247
Tables 248
Normalization 249
SQL and Stored Procedures 251
The Web Matrix Data Explorer 251
Try It Out Connecting to a Database 251
Creating Data Pages 253
Displaying Data Using the Data Explorer 253
Try It Out Creating a Grid 253
Displaying Data Using the Web Matrix Template Pages 256

Try It Out Creating a Data Page 257
Displaying Data Using the Code Wizards 262
Try It Out Creating a Data Page 262
ADO.NET 269
The OleDbConnection Object 271
The OleDbCommand Object 271
Try It Out Using Parameters 273
The OleDataAdapter Object 278
The DataSet Object 278
The DataReader Object 278
Try It Out Using a DataReader 279
Summary 281
Exercises 281
Chapter 9: Advanced Data Handling 283
More Data Objects 283
The DataTable Object 284
The DataRow Object 285
Try It Out The DataTable and DataRow Objects 286
Updating Databases 288
ADO.NET versus ADO 289
Updating Data in a DataSet 289
Try It Out Adding, Editing, and Deleting Rows 289
Updating the Original Data Source 297
Try It Out Auto-Generated Commands 298
Updating the Database 301
xiv
Contents
Try It Out Updating the Database 302
Updating Databases Using a Command 307
Try It Out Executing Commands Directly 307

Summary 310
Exercises 311
Chapter 10: ASP.NET Server Controls 313
The Wrox United Application 314
ASP.NET Web Controls 315
HTML Server Controls 316
HTML Server Controls versus Web Controls 318
Web Controls 319
Rich Object Model 320
Automatic Browser Detection 320
Properties 320
Events 322
Try It Out Creating an Event Handler 322
Page Lifecycle 324
Page_Load() 325
Event Handling 326
Page_Unload() 326
Understanding Web Controls: The Wrox United Application 327
Try It Out Wrox United Main Page – Default.aspx 328
Intrinsic Controls 331
Try It Out Wrox United – Teams.aspx 332
Data Rendering Controls 340
Try It Out Wrox United – Teams.aspx, Part 2 343
Rich Controls 352
Try It Out Wrox United – Default.aspx, Part 2, the Event Calendar 354
Try It Out Wrox United – Displaying Fixture Details 360
Web Matrix Controls 366
Try It Out Wrox United – Players.aspx and the Web Matrix MX DataGrid 367
Validation Controls 372
Try It Out Wrox United – Registering for Email Updates (Default.aspx) 373

Summary 378
Exercises 378
Chapter 11: Users and Applications 381
Remembering Information in a Web Application 382
Cookies 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 410
Global.asax 410
xv
Contents
Try it Out Global.asax – Global Settings 411
Caching 413
Try It Out Wrox United – Caching Objects 415
State Management Recommendations 418
When to Use Cookies 419
When to Use Sessions 419
When to Use Applications 419
When to Use Caching 419
Other State Management Techniques 420
Using Multiple State Management Techniques on a Page 421
Try it Out Wrox United – Adding Some Style! 421
Summary 429
Exercises 430
Chapter 12: Reusable Code for ASP.NET 431
Encapsulation 431

Components 432
Why Use Components? 434
Applying Component Theory to Applications 434
User Controls 435
Try It Out Our First User Control 437
Try It Out Wrox United – Header Control 440
Try It Out Wrox United – Navigation User Control 446
Code-Behind 451
Try It Out Our First Code-Behind File 452
Try It Out Using Code-Behind in Wrox United 457
Summary 459
Exercises 459
Chapter 13: .NET Assemblies and Custom Controls 463
Three-Tier Application Design 464
ASP.NET Application Design 465
.NET Assemblies 466
Try It Out Our First ASP.NET Component 467
What Is Compilation? 470
Try It Out Compiling Our First ASP.NET Component 470
Accessing a Component from within an ASP.NET Page 474
Try It Out Using a Compiled Component 474
XCopy Deployment 476
Accessing Assemblies in Other Locations 477
Writing Code in Other Languages 477
Try It Out Writing a Component in VB.NET 478
Data Access Components 482
Try It Out Encapsulating Data Access Code in a Component 482
Custom Server Controls 489
What Are Custom Controls? 490
Try It Out Our First ASP.NET Custom Control 491

Composite Custom Controls 499
xvi
Contents
Try It Out Wrox United – Custom Composite Control 499
Summary 506
Exercises 507
Chapter 14: Debugging and Error Handling 509
A Few Good Habits 510
Tips on Coding 510
Indent Your Code 511
Structure Your Code 511
Comment Your Code 512
Convert Variables to the Correct Data Types (Validation) 512
Try to Break Your Code 513
Sources of Errors 514
Syntax Errors 514
Try It Out Syntax Error 515
Try It Out Generate a Compiler Error 516
Logical (Runtime) Errors 518
Try It Out Generate a Runtime Error 519
Try It Out Catching Illegal Values 521
Try It Out Using RequiredFieldValidator 524
System Errors 525
Finding Errors 525
Try It Out Viewing the Call-Stack 526
Debug Mode 527
Try It Out Disable the Debug Mode 527
Tracing 529
Try It Out Enabling Trace at the Page Level 529
Try It Out Writing to the Trace Log 532

Handling Errors 535
Try It Out Using try catch finally 542
Try It Out Using Page_Error() 548
Error Notification and Logging 550
Try It Out Creating Error Pages 551
Writing to the Event Log 553
Try It Out Writing to the Windows Error Log 554
Mailing the Site Administrator 557
Summary 559
Exercises 559
Chapter 15: Configuration and Optimization 561
Configuration Overview 562
Browsing .config Files 562
The Configuration Files 564
The Structure of the Configuration Files 567
Performance Optimization 574
Caching 574
Try It Out Output Caching 576
The Cache Object 578
xvii
Contents
Expiring Information in the Cache 581
Try It Out Creating a File Dependency 582
Try It Out Creating a Key Dependency 586
Tips and Tricks 590
Summary 591
Exercises 591
Chapter 16: Web Services 593
What Is a Web Service? 594
Try It Out Creating Our First Web Service 595

HTTP, XML, and Web Services 598
HTTP GET 599
HTTP POST 600
Simple Object Access Protocol (SOAP) 601
Building an ASP.NET Web Service 603
Processing Directive 603
Namespaces 603
Public Class 604
Web Methods 604
Try It Out Creating a Web Service with Multiple Web Methods 605
Testing Your Web Service 607
Try It Out Conversions Test Page 607
Using Your Web Service 608
Try It Out Viewing the WSDL Contract 609
Try It Out ISBN Search Web Service 610
Consuming a Web Service 613
How Does a Proxy Work? 613
Creating a Proxy 615
Try It Out Accessing the ISBN Web Service from an ASP.NET Page 615
Creating a Web Service for the Wrox United Application 618
Try It Out Adding a Results Page 619
Try It Out Creating the Web Service 621
Web Service Discovery 626
Securing a Web Service 627
Username-Password Combination or Registration Keys 627
Try It Out Securing a Web Service with Username and Password 627
Secure Sockets Layer (SSL) 630
IP Address Restriction 630
Web Services Enhancements (WSE) 631
Other Web Services Considerations 631

Network Connectivity 631
Asynchronous Method Calls 631
Service Hijacking (or Piggybacking) 632
Provider Solvency 633
The Interdependency Scenario 633
Summary 633
Exercises 634
xviii
Contents
Chapter 17: ASP.NET Security 635
What Is Security? 636
The ASP.NET Security Model 636
Authentication 637
Implementing Forms-Based Authentication 638
Try It Out Forms-Based Authentication 639
Forms-Based Authentication Using a Database 646
Try It Out Authenticating against a Database 646
Authorization 650
Try It Out Authorization for 651
Authentication in Wrox United 653
Try It Out Adding a Login Page to WroxUnited 653
Encryption Using SSL 664
Try It Out Enabling SSL 665
Summary 666
Exercises 666
Appendix A: Exercise Solutions 667
Chapter 2 667
Chapter 3 669
Chapter 4 672
Chapter 5 675

Chapter 6 678
Chapter 7 681
Chapter 8 684
Chapter 9 686
Chapter 10 688
Chapter 11 693
Chapter 12 697
Chapter 13 702
Chapter 14 708
Chapter 15 713
Chapter 16 715
Chapter 17 720
Appendix B: Web Matrix Quick Start 725
What Is Web Matrix? 725
Starting ASP.NET Web Matrix 727
The Screen 727
How to Enter Code 730
Try It Out Code Entry 731
Saving and Viewing Pages 731
Try It Out Formatting Modes, Views, and Serving Pages 733
Reusing Code 735
Try It Out Saving and Using Snippets 735
xix
Contents
Class Browser 735
Try It Out Class Browser Property Look-Up 736
What to Study Next 738
Summary 738
Appendix C: The Wrox United Database 741
The Database Design 741

Players 742
Status 742
Teams 743
PlayerTeams 743
Positions 744
Games 744
GameTypes 745
Locations 745
Opponents 746
Fans 746
Installing the Database 747
Installing the Access Database 747
Installing the MSDE Database 747
Appendix D: Web Application Development Using Visual Studio .NET 753
Creating a Web Application Project 754
Features of the Visual Studio .NET Environment 755
Visual Studio .NET Solutions and Projects 756
Files in a Web Application Project 757
Working with Web Pages 757
Compiling and Running Pages 761
Adding Code to the Code-Behind Class 762
Features of Code View 763
Adding Code to Methods 763
Styling Controls and Pages in Visual Studio .NET 769
Working in HTML View 776
Creating User Controls 777
Formatting Blocks of Code 782
Developing the User Control 784
Creating an XML File 786
Adding a User Control to a Page 789

Adding Custom Classes 791
Working with Databases Using the Server Explorer 794
Debugging in Visual Studio .NET 797
Using Breakpoints 798
Fixing Design-Time Errors 799
Suggested Exercises and Further Reading 801
xx
Contents
Appendix E: Installing and Configuring IIS 803
Try It Out Locating and Installing IIS on Your Web Server Machine 803
Working with IIS 806
The Microsoft Management Console (MMC) 806
Testing Your Installation 807
Identifying Your Web Server's Name 807
Managing Directories on Your Web Server 808
Try It Out Creating a Virtual Directory and Setting Up Permissions 810
Permissions 814
Browsing to a Page on Your Web Server 818
Index 825
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.
xxii
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

×