He’s a regular contributor to programming journals, and the author of more than a dozen books about .NET programming, including Pro ASP.NET 2.0 in C# 2005 Apress, Microsoft .NET Distribu
Trang 3Beginning ASP.NET 2.0 in VB 2005: From Novice to Professional
Copyright © 2006 by Matthew MacDonald
All rights reserved No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.
ISBN-13 (pbk): 978-1-59059-621-0
ISBN-10 (pbk): 1-59059-621-8
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book Rather than use a trademark symbol with every occurrence
of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
Lead Editor: Ewan Buckingham
Technical Reviewer: Andy Olsen
Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jason Gilmore, Jonathan Gennick, Jonathan Hassell, James Huddleston, Chris Mills, Matthew Moodie, Dominic Shakeshaft, Jim Sumser, Keir Thomas, Matt Wade
Project Manager | Production Director: Grace Wong
Copy Edit Manager: Nicole LeClerc
Copy Editors: Jennifer Whipple, Kim Wimpsett
Assistant Production Director: Kari Brooks-Copony
Production Editor: Kelly Winquist
Compositor and Artist: Kinetic Publishing Services, LLC
Proofreaders: Lori Bring, Elizabeth Berry
Indexer: Michael Brinkman
Cover Designer: Kurt Krames
Manufacturing Director: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013 Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com, or visit http://www.springeronline.com
For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA
94710 Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com, or visit http://www.apress.com The information in this book is distributed on an “as is” basis, without warranty Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly
by the information contained in this work
The source code for this book is available to readers at http://www.apress.com in the Source Code section
Trang 4For Faria
Trang 6Contents at a Glance
About the Author xxvii
About the Technical Reviewer xxix
Acknowledgments xxxi
Introduction xxxiii
PART 1 ■ ■ ■ Introducing NET ■ CHAPTER 1 Introducing the NET Framework 3
■ CHAPTER 2 Learning the VB 2005 Language 21
■ CHAPTER 3 Types, Objects, and Namespaces 51
■ CHAPTER 4 Introducing Visual Studio 2005 85
PART 2 ■ ■ ■ Developing ASP.NET Applications ■ CHAPTER 5 Web Form Fundamentals 119
■ CHAPTER 6 Web Controls 167
■ CHAPTER 7 Tracing, Logging, and Error Handling 209
■ CHAPTER 8 Validation and Rich Controls 255
■ CHAPTER 9 State Management 303
■ CHAPTER 10 Master Pages and Themes 343
■ CHAPTER 11 Website Navigation 373
■ CHAPTER 12 Deploying ASP.NET Applications 411
PART 3 ■ ■ ■ Working with Data ■ CHAPTER 13 ADO.NET Fundamentals 451
■ CHAPTER 14 Data Binding 515
■ CHAPTER 15 The Data Controls 557
■ CHAPTER 16 Files and Streams 601
■ CHAPTER 17 XML 631
v
Trang 7PART 4 ■ ■ ■ Website Security
■ CHAPTER 18 Security Fundamentals 681
■ CHAPTER 19 Membership 713
■ CHAPTER 20 Profiles 755
PART 5 ■ ■ ■ Web Services ■ CHAPTER 21 Web Services Architecture 785
■ CHAPTER 22 Creating Web Services 797
■ CHAPTER 23 Enhancing Web Services 835
PART 6 ■ ■ ■ Advanced ASP.NET ■ CHAPTER 24 Component-Based Programming 867
■ CHAPTER 25 Custom Controls 901
■ CHAPTER 26 Caching and Performance Tuning 951
■ INDEX 993
vi
Trang 8About the Author xxvii
About the Technical Reviewer xxix
Acknowledgments xxxi
Introduction xxxiii
PART 1 ■ ■ ■ Introducing NET ■ CHAPTER 1 Introducing the NET Framework 3
The Evolution of Web Development 3
HTML and HTML Forms 4
Server-Side Programming 6
Client-Side Programming 7
The Problems with ASP 9
The NET Framework 10
VB 2005, C#, and the NET Languages 12
The Intermediate Language 12
Other NET Languages 14
The Common Language Runtime 14
The NET Class Library 16
Visual Studio 2005 17
.NET 2.0 18
ASP.NET 2.0 18
Visual Studio 2005 20
The Last Word 20
■ CHAPTER 2 Learning the VB 2005 Language 21
The NET Languages 21
The Evolution of Visual Basic 22
vii
Trang 9Variables and Data Types 23
Assignment and Initializers 25
Arrays 26
Enumerations 28
Variable Operations 30
Advanced Math 31
Type Conversions 32
Object-Based Manipulation 34
The String Type 35
The DateTime and TimeSpan Types 36
The Array Type 39
Conditional Structures 39
The If End If Block 40
The Select Case Block 41
Loop Structures 41
The For Next Block 42
The For Each Block 43
The Do Loop Block 44
Methods 45
Parameters 46
Method Overloading 47
Delegates 48
The Last Word 50
■ CHAPTER 3 Types, Objects, and Namespaces 51
The Basics of Classes 51
Shared and Instance Members 53
A Simple Class 54
Building a Basic Class 54
Creating an Object 55
Adding Properties 56
Adding a Basic Method 59
Adding a Constructor 60
Adding a Basic Event 61
Testing the Product Class 64
Value Types and Reference Types 67
Assignment Operations 67
Equality Testing 68
Passing Parameters by Reference and by Value 68
Reviewing NET Types 70
Trang 10Understanding Namespaces and Assemblies 71
Using Namespaces 73
Importing Namespaces 74
Assemblies 74
Advanced Class Programming 75
Inheritance 76
Shared Members 77
Casting Objects 78
Partial Classes 81
Generics 82
The Last Word 84
■ CHAPTER 4 Introducing Visual Studio 2005 85
The Promise of Visual Studio 85
Creating a Website 87
The Solution Explorer 90
Designing a Web Page 92
Adding Web Controls 93
The Properties Window 95
Adding Ordinary HTML 96
HTML Tables 98
Writing Code 100
Adding Event Handlers 100
IntelliSense and Outlining 102
Assembly References 107
Namespace Imports 108
Visual Studio Debugging 110
Single-Step Debugging 110
Variable Watches 114
The Last Word 115
PART 2 ■ ■ ■ Developing ASP.NET Applications ■ CHAPTER 5 Web Form Fundamentals 119
The Anatomy of an ASP.NET Application 119
ASP.NET File Types 121
ASP.NET Application Directories 122
Application Updates 123
Trang 11A Simple One-Page Web Application 124
The ASP Solution—and Its Problems 126
The ASP.NET Solution: Server Controls 127
HTML Server Controls 128
View State 130
The HTML Control Classes 131
Improving the Currency Converter 139
Adding Multiple Currencies 139
Storing Information in the List 141
Adding Linked Images 142
Setting Styles 144
A Deeper Look at HTML Control Classes 145
HTML Control Events 146
Advanced Events with the HtmlInputImage Control 147
The HtmlControl Base Class 149
The HtmlContainerControl Class 150
The HtmlInputControl Class 150
The Page Class 151
The Controls Collection 152
The HttpRequest Class 153
The HttpResponse Class 154
The HttpServerUtility Class 154
ASP.NET Configuration 157
The web.config File 158
Nested Configuration 159
Storing Custom Settings in the web.config File 160
Modifying web.config Settings Programmatically 163
The Website Administration Tool (WAT) 164
The Last Word 166
■ CHAPTER 6 Web Controls 167
Stepping Up to Web Controls 167
Basic Web Control Classes 168
The Web Control Tags 169
Trang 12Web Control Classes 171
The WebControl Base Class 172
Units 173
Enumerated Values 174
Colors 174
Fonts 175
Focus 177
The Default Button 178
List Controls 178
Multiple-Select List Controls 179
The BulletedList Control 182
Table Controls 184
Web Control Events and AutoPostBack 189
How Postback Events Work 193
The Page Life Cycle 194
A Simple Web Page 197
Improving the Greeting Card Applet 202
Generating the Cards Automatically 205
The Last Word 207
■ CHAPTER 7 Tracing, Logging, and Error Handling 209
Common Errors 209
Exception Handling 211
The Exception Class 212
The Exception Chain 213
Handling Exceptions 214
Catching Specific Exceptions 215
Nested Exception Handlers 216
Exception Handling in Action 218
Mastering Exceptions 220
Throwing Your Own Exceptions 220
Logging Exceptions 225
Using the EventLog Class 227
Custom Logs 230
Retrieving Log Information 231
Error Pages 234
Error Modes 236
A Custom Error Page 237
Specific Custom Error Pages 238
Trang 13Page Tracing 239
Enabling Tracing 240
Tracing Information 241
Writing Trace Information 247
Application-Level Tracing 251
The Last Word 253
■ CHAPTER 8 Validation and Rich Controls 255
Validation 255
The Validation Controls 256
The Validation Process 257
Client-Side Validation 258
The Validator Classes 258
A Simple Validation Example 259
Other Display Options 262
Manual Validation 264
Understanding Regular Expressions 266
Literals and Metacharacters 266
Finding a Regular Expression 267
A Validated Customer Form 270
Validation Groups 275
Rich Controls 277
The Calendar Control 278
The AdRotator 286
Pages with Multiple Views 289
The MultiView Control 290
The Wizard Control 295
The Last Word 302
■ CHAPTER 9 State Management 303
The Problem of State 303
View State 304
A View State Example 304
Making View State Secure 306
Trang 14Retaining Member Variables 307
Storing Custom Objects 309
Transferring Information 311
Cross-Page Posting 311
The Query String 316
Custom Cookies 320
A Cookie Example 322
Session State 323
Session Tracking 324
Using Session State 324
A Session State Example 326
Session State Configuration 329
Cookieless 330
Timeout 333
Mode 333
Application State 337
An Overview of State Management Choices 339
The Global.asax Application File 340
Application Events 342
The Last Word 342
■ CHAPTER 10 Master Pages and Themes 343
Master Page Basics 343
A Simple Master Page and Content Page 345
How Master Pages and Content Pages Are Connected 348
A Master Page with Multiple Content Regions 350
Default Content 353
Master Pages and Relative Paths 354
Advanced Master Pages 355
Table-Based Layouts 355
Code in a Master Page 360
Interacting with a Master Page Programmatically 360
Themes 362
How Themes Work 363
Applying a Simple Theme 365
Trang 15Handling Theme Conflicts 366
Creating Multiple Skins for the Same Control 368
Skins with Templates and Images 369
The Last Word 372
■ CHAPTER 11 Website Navigation 373
Site Maps 373
Defining a Site Map 374
Seeing a Simple Site Map in Action 379
Binding an Ordinary Page to a Site Map 380
Binding a Master Page to a Site Map 381
Binding Portions of a SiteMap 383
Navigating Programmatically 389
Mapping URLs 391
The SiteMapPath Control 393
Customizing the SiteMapPath 394
Using SiteMapPath Styles and Templates 394
Adding Custom Site Map Information 396
The TreeView Control 397
TreeView Properties 398
TreeView Styles 399
The Menu Control 404
Menu Styles 406
Menu Templates 407
The Last Word 410
■ CHAPTER 12 Deploying ASP.NET Applications 411
ASP.NET Applications and the Web Server 411
How Web Servers Work 411
Web Application URLs 413
Web Farms 415
IIS (Internet Information Services) 416
Installing IIS 5 417
Installing IIS 6 418
Trang 16Registering the ASP.NET File Mappings 420
Verifying That ASP.NET Is Correctly Installed 421
Managing Websites with IIS Manager 422
Creating a Virtual Directory 423
Virtual Directories and Web Applications 426
Configuring an Existing Virtual Directory 428
Adding a Virtual Directory to Your Neighborhood 434
Deploying a Simple Site 436
Web Applications and Components 437
Other Configuration Steps 437
The ASPNET Account 438
Code Compilation 441
Deploying with Visual Studio 2005 442
Creating a Virtual Directory for a New Project 443
Copying a Website 446
Publishing a Website 448
The Last Word 450
PART 3 ■ ■ ■ Working with Data ■ CHAPTER 13 ADO.NET Fundamentals 451
ADO.NET and Data Management 451
The Role of the Database 452
Database Access in the Internet World 453
Introducing ADO.NET 454
SQL Server 2005 Express Edition 456
Browsing and Modifying Databases in Visual Studio 456
SQL Basics 458
Running Queries in Visual Studio 459
The Select Statement 461
The SQL Update Statement 464
The SQL Insert Statement 465
The SQL Delete Statement 466
Trang 17ADO.NET Basics 467
Data Namespaces 469
The Data Provider Objects 469
Direct Data Access 471
Importing the Namespaces 472
Creating a Connection 472
The Connection String 473
Windows Authentication 474
Connection String Tips 475
Making the Connection 476
Defining a Select Command 478
Using a Command with a DataReader 479
Putting It All Together 480
Filling the List Box 481
Updating Data 484
Enhancing the Author Page 485
Creating More Robust Commands 489
Disconnected Data Access 495
Selecting Disconnected Data 496
Selecting Multiple Tables 498
Modifying Disconnected Data 503
Adding Rows to a DataSet 504
Updating Disconnected Data 505
The CommandBuilder 505
Updating a DataTable 506
Controlling Updates 506
A Disconnected Update Example 508
Concurrency Problems 510
A Concurrency Example 511
The Last Word 514
■ CHAPTER 14 Data Binding 515
Introducing Data Binding 515
Types of ASP.NET Data Binding 516
How Data Binding Works 516
Trang 18Single-Value Data Binding 517
A Simple Data Binding Example 518
Simple Data Binding with Properties 521
Problems with Single-Value Data Binding 522
Using Code Instead of Simple Data Binding 523
Repeated-Value Data Binding 524
Data Binding with Simple List Controls 524
A Simple List Binding Example 525
Generic Collections 527
Multiple Binding 527
Data Binding and View State 530
Data Binding with a Dictionary Collection 530
Using the DataValueField Property 532
Data Binding with ADO.NET 533
Creating a Record Editor 535
Data Source Controls 541
The Page Life Cycle with Data Binding 542
The SqlDataSource 543
Selecting Records 545
Parameterized Commands 547
Handling Errors 551
Updating Records 551
The Last Word 555
■ CHAPTER 15 The Data Controls 557
The GridView 557
Automatically Generating Columns 558
Defining Columns 560
Formatting the GridView 564
Formatting Fields 564
Using Styles 566
Formatting-Specific Values 569
Selecting a GridView Row 571
Adding a Select Button 572
Using Selection to Create Master-Details Pages 574
Trang 19Editing with the GridView 576
Sorting and Paging the GridView 579
Sorting 579
Paging 582
Using GridView Templates 585
Using Multiple Templates 587
Editing Templates in Visual Studio 588
Handling Events in a Template 589
Editing with a Template 590
The DetailsView and FormView 595
The DetailsView 596
The FormView 599
The Last Word 600
■ CHAPTER 16 Files and Streams 601
Files and Web Applications 601
File System Information 602
The Directory and File Classes 603
The DirectoryInfo and FileInfo Classes 608
The DriveInfo Class 610
A Sample File Browser 611
Reading and Writing with Streams 615
Text Files 615
Binary Files 617
Shortcuts for Reading and Writing Files 619
A Simple Guest Book 620
Allowing File Uploads 625
The FileUpload Control 625
The HtmlInputFile Control 629
The Last Word 629
■ CHAPTER 17 XML 631
XML’s Hidden Role in NET 631
Configuration Files 631
ADO.NET Data Access 632
Trang 20Web Services 632
Anywhere Miscellaneous Data Is Stored 632
XML Explained 632
Improving the List with XML 634
XML Basics 636
Attributes 637
Comments 639
The XML Classes 639
The XML TextWriter 640
The XML Text Reader 642
Working with XML Documents in Memory 648
Reading an XML Document 653
Searching an XML Document 656
XML Validation 657
XML Namespaces 657
XSD Documents 659
Validating an XML Document 660
XML Display and Transforms 663
The Xml Web Control 666
XML Data Binding 667
Nonhierarchical Binding 668
Hierarchical Binding with the TreeView 670
Binding to XML Content from Other Sources 672
XML in ADO.NET 673
Accessing a DataSet As XML 674
Accessing XML Through the DataSet 676
The Last Word 678
PART 4 ■ ■ ■ Website Security ■ CHAPTER 18 Security Fundamentals 681
Determining Security Requirements 681
Restricted File Types 682
Security Concepts 682
Trang 21The ASP.NET Security Model 683
Security Strategies 686
Certificates 686
Secure Sockets Layer 688
Forms Authentication 689
Web.config Settings 691
Authorization Rules 692
The WAT 695
The Login Page 698
Windows Authentication 703
IIS Settings 703
Web.config Settings 705
A Windows Authentication Test 707
Impersonation 709
Programmatic Impersonation 710
The Last Word 711
■ CHAPTER 19 Membership 713
The Membership Data Store 714
Membership with SQL Server 2005 715
Configuring the Membership Provider 718
Manually Creating the Membership Tables 723
Creating Users with the WAT 725
The Membership and MembershipUser Classes 727
Authentication with Membership 731
Disabled Accounts 732
The Security Controls 733
The Login Control 734
The CreateUserWizard Control 739
The PasswordRecovery Control 744
Role-Based Security 746
Creating and Assigning Roles 747
Restricting Access Based on Roles 750
The LoginView Control 751
The Last Word 753
Trang 22■ CHAPTER 20 Profiles 755
Understanding Profiles 756
Profile Performance 756
How Profiles Store Data 757
Using the SqlProfileProvider 759
Enabling Authentication 759
Profiles with SQL Server 2005 Express Edition 760
Configuring the Profile Provider to Use a Different Database 761
Manually Creating the Profile Tables 763
The Profile Databases 764
Defining Profile Properties 766
Using Profile Properties 767
Profile Serialization 769
Profile Groups 771
Profiles and Custom Data Types 772
The Profile API 777
Anonymous Profiles 779
The Last Word 782
■ CHAPTER 21 Web Services Architecture 785
Internet Programming Then and Now 785
Components and the COM Revolution 786
Web Services and the Programmable Web 787
When Web Services Make Sense 787
The Open-Standards Plumbing 788
Web Services Description Language 789
A Sample SOAP Message 790
Communicating with a Web Service 791
Web Service Discovery 792
Trang 23■ CHAPTER 22 Creating Web Services 797
Web Service Basics 797
Configuring a Web Service Project 798
The StockQuote Web Service 800
Understanding the StockQuote Service 801
Web Services with Code-Behind 801
The ASP.NET Intrinsic Objects 803
Documenting Your Web Service 804
Descriptions 804
The XML Namespace 805
Conformance Claims 806
Testing Your Web Service 807
The Web Service Test Page 808
Service Description 809
Method Description 810
Testing a Method 811
Web Service Data Types 813
The StockQuote Service with a Data Object 814
Consuming a Web Service 818
Configuring a Web Service Client in Visual Studio 818
The Role of the Proxy Class 819
Creating a Web Reference in Visual Studio 820
Creating a Proxy with WSDL.exe 822
Dissecting the Proxy Class 824
Dynamic Web Service URLs 827
Using the Proxy Class 828
Waiting and Timeouts 829
Web Service Errors 830
Connecting Through a Proxy 831
The Last Word 831
■ CHAPTER 23 Enhancing Web Services 835
State Management 835
The StockQuote Service with State Management 836
Consuming a Stateful Web Service 838
Trang 24Web Service Security 842
Windows Authentication with a Web Service 843
Ticket-Based Authentication 847
Ticket-Based Authentication with SOAP Headers 849
Using SOAP Headers in the Client 852
Web Service Transactions 853
An Example with TerraService 855
Adding the Reference 856
Testing the Client 857
Searching for More Information 859
Displaying a Tile 860
Windows Clients 862
The Last Word 864
■ CHAPTER 24 Component-Based Programming 867
Why Use Components? 867
Classes and Namespaces 874
Adding a Reference to the Component 876
Using the Component 878
Properties and State 880
A Stateful Account Class 881
A Stateless AccountUtility Class 882
Data-Access Components 883
A Simple Data-Access Component 884
Using the Data-Access Component 888
Trang 25Enhancing the Component with Error Handling 891
Enhancing the Component with Aggregate Information 892
The Last Word 899
■ CHAPTER 25 Custom Controls 901
User Controls 901
Creating a Simple User Control 902
Independent User Controls 905
Integrated User Controls 907
User Control Events 910
Passing Information with Events 912
User Control Limitations 916
Custom Controls 916
Creating a Simple Derived Control 917
Creating a Custom Control Library 919
Using a Custom Control 920
Custom Controls and Default Values 923
Changing Control Rendering 925
Creating a Web Control from Scratch 929
Maintaining State Information 931
Design-Time Support 934
Creating a Composite Control 935
Custom Control Events and Postbacks 937
Dynamic Graphics 943
Basic Drawing 943
Drawing Custom Text 946
Placing Custom Images Inside Web Pages 947
The Last Word 949
Trang 26■ CHAPTER 26 Caching and Performance Tuning 951
Designing for Performance 952
ASP.NET Code Compilation 952
Caching on the Client Side 962
Caching and the Query String 963
Caching with Specific Parameters 964
A Multiple Caching Example 965
Custom Caching Control 966
Fragment Caching 968
Cache Profiles 968
Output Caching in a Web Service 969
Data Caching 970
Adding Items to the Cache 970
A Simple Cache Test 971
Caching to Provide Multiple Views 973
Data Caching in a Web Service 976
Caching with the Data Source Controls 978
Caching with Dependencies 982
Cache Notifications in SQL Server 2000 or SQL Server 7 984
Cache Notifications in SQL Server 2005 988
The Last Word 992
■ INDEX 993
Trang 28About the Author
■MATTHEW MACDONALD is an author, educator, and MCSD developer
He’s a regular contributor to programming journals, and the author of
more than a dozen books about NET programming, including Pro
ASP.NET 2.0 in C# 2005 (Apress), Microsoft NET Distributed Applications
(Microsoft Press), Programming NET Web Services (O’Reilly), and
ASP.NET: The Complete Reference (Osborne McGraw-Hill) In a dimly
remembered past life, he studied English literature and theoreticalphysics You can read about his books at http://www.prosetech.com
xxvii
Trang 30About the Technical Reviewer
■ANDY OLSENis a freelance developer, instructor, and writer based in Swansea in Wales
Andy has been using Microsoft technologies for 20 years, back in the days when the words
“Visual Basic” were a contradiction in terms Andy would like to thank his wife Jayne for
her patience against all the odds, and Emily and Thomas for all the fun Cymru am Byth!
xxix
Trang 32No author could complete a book without a small army of helpful individuals I’m deeply
indebted to the whole Apress team, including Grace Wong and Kelly Winquist, who helped
everything move swiftly and smoothly; Jennifer Whipple and Kim Wimpsett, who performed
the copy edit; Andy Olsen, who performed the most recent round of technical review; and
many other individuals who worked behind the scenes indexing pages, drawing figures,
and proofreading the final copy I owe a special thanks to Gary Cornell, who’s built a truly
unique company with Apress
I’d also like to thank those who were involved with previous editions of this book
This includes Emma Acker and Jane Brownlow at Osborne McGraw-Hill and previous
tech reviewers Ronald Landers, Gavin Smyth, Tim Verycruysse, and Julian Skinner I also
owe a hearty thanks to all the readers who caught errors and took the time to report
prob-lems and ask good questions Keep sending in the feedback—it helps make better books!
Finally, I’d never write any book without the support of my wife and these special
individuals: Nora, Razia, Paul, and Hamid Thanks, everyone!
xxxi
6e067a1cf200c3b6e021f18882237192
Trang 34ASP (Active Server Pages) is a web development technology that's leapt through several
stages of evolution It was first introduced as an easy way to add dynamic content to
ordi-nary web pages Since then, it’s grown into something much more ambitious: a platform for
creating advanced web applications, including e-commerce shops, data-driven portal sites,
and just about anything else you can find on the Internet
ASP.NET 2.0 is the latest version of ASP, and it represents the most dramatic change yet
With ASP.NET, developers no longer need to paste together a jumble of HTML and script
code in order to program the Web Instead, you can create full-scale web applications using
nothing but code and a design tool such as Visual Studio 2005 The cost of all this innovation
is the learning curve Not only do you need to learn how to use an advanced design tool
(Visual Studio) and a toolkit of objects (the NET Framework), you also need to master a
pro-gramming language such as Visual Basic 2005
Beginning ASP.NET 2.0 in VB 2005 assumes you want to master ASP.NET, starting from
the basics Using this book, you’ll build your knowledge until you understand the concepts,
techniques, and best practices for writing sophisticated web applications The journey is
long, but it’s also satisfying At the end of the day, you’ll find that ASP.NET allows you to
tackle challenges that are simply out of reach on many other platforms You’ll also become
part of the fast-growing ASP.NET developer community
About This Book
This book explores ASP.NET, which is a core part of Microsoft’s NET Framework The NET
Framework is not a single application—it’s actually a collection of technologies bundled
into one marketing term The NET Framework includes languages such as C# and VB 2005,
an engine for hosting programmable web pages and web services (ASP.NET), a model for
interacting with databases (ADO.NET), and a class library stocked with tools for everything
from sending e-mail to encrypting a password To master ASP.NET, you need to learn about
each of these ingredients
This book covers all these topics from the ground up As a result, you’ll find yourselflearning many techniques that will interest any NET developer, even those who create
Windows applications For example, you’ll learn about component-based programming,
you’ll discover structured error handling, and you’ll see how to access files, XML, and
relational databases You’ll also learn the key topics you need for web programming, such
as state management, web controls, and web services By the end of this book, you’ll be ready
to create your own rich web applications and make them available over the Internet
xxxiii
Trang 35■ Note This book has a single goal: to be as relentlessly practical as possible I take special care not toleave you hanging in the places where other ASP.NET books abandon their readers For example, whenencountering a new technology, you’ll not only learn how it works but also why (and when) you should use it.
I also highlight common questions and best practices with tip boxes and sidebars at every step of the way.Finally, if a topic is covered in this book, it’s covered right This means you won’t learn how to perform a taskwithout learning about potential drawbacks and the problems you might run into—and how you can safe-guard yourself with real-world code
Who Should Read This Book
This book is aimed at anyone who wants to create dynamic websites with ASP.NET Ideally,you have experience with a previous version of a programming language such as VisualBasic 6 or Java If not, you should be familiar with basic programming concepts (loops,conditional structures, arrays, and so on), whether you’ve learned them in C, Pascal,Turing, or a completely different programming language This is the only requirement forreading this book Understanding HTML helps, but it’s not required ASP.NET works at
a higher level, allowing you to deal with full-featured web controls instead of raw HTML.You also don’t need any knowledge of XML, because Chapter 17 covers it in detail.This book will also appeal to programmers who have some experience with VisualBasic and NET but haven’t worked with ASP.NET in the past However, if you’ve used
a previous version of ASP.NET, you’ll probably be more interested in a faster-paced book
such as Pro ASP.NET 2.0 in VB 2005 (Apress, 2006) instead.
■ Note This book begins with the fundamentals: VB syntax, the basics of object-oriented programming,and the philosophy of the NET Framework If you haven’t worked with VB 2005 before, you can spend a littlemore time with the syntax review in Chapter 2 to pick up everything you need to know If you aren’t familiarwith the ideas of object-oriented programming, Chapter 3 fills in the blanks with a quick, but comprehensive,review of the subject The rest of the book builds on this foundation, from ASP.NET basics to advanced exam-ples that show the techniques you’ll use in real-world web applications
What You Need to Use This Book
The main prerequisite for this book is a computer with Visual Studio 2005 You can alsouse the scaled-down Visual Studio Web Developer 2005 Express Edition, but you’ll runinto a few minor limitations Most significantly, you can’t use Visual Studio Web Devel-oper to create class libraries (separate components), a technique discussed in Chapter 24.(However, you still use the sample code directly in your web projects.)
To run ASP.NET pages, you need Windows 2000 Professional, Windows XP Professional,Windows 2000 Server, or Windows Server 2003 You also need to install IIS (Internet
Trang 36Information Services), the web hosting software that’s part of the Windows operating
system, if you want to try web services or test deployment strategies
Finally, this book includes several examples that use SQL Server You can use anyversion of SQL Server to try these, including SQL Server 2005 Express Edition, which is
included with some versions of Visual Studio (and freely downloadable at http://msdn
microsoft.com/sql/express) If you use other relational database engines, the same
con-cepts will apply; you will just need to modify the example code
Code Samples
To master ASP.NET, you need to experiment with it One of the best ways to learn ASP.NET
is to try the code samples for this book, examine them, and dive in with your own
modifi-cations To obtain the sample code, surf to http://www.prosetech.comor the publisher’s
website at http://www.apress.com You’ll also find some links to additional resources and
any updates or errata that affect the book
Chapter Overview
This book is divided into six parts Unless you’ve already had experience with the NET
Framework, the most productive way to read this book is in order from start to finish
Chapters later in the book sometimes incorporate features that were introduced earlier in
order to create more well-rounded and realistic examples On the other hand, if you’re already
familiar with the NET platform, VB, and object-oriented programming, you’ll make short
work of the first part of this book
Part 1: Introducing NET
You could start coding an ASP.NET application right away by following the examples in
the second part of this book But to really master ASP.NET, you need to understand a few
fundamental concepts about the NET Framework
Chapter 1 sorts through the Microsoft jargon and explains what the NET Frameworkreally does and why you need it Chapter 2 introduces you to VB 2005 with a comprehensive
language reference, and Chapter 3 explains the basics of modern object-oriented
program-ming Chapter 4 introduces the Visual Studio design environment
Part 2: Developing ASP.NET Applications
The second part of this book delves into the heart of ASP.NET programming and introduces
its new event-based model In Chapters 5 and 6, you learn how to program a web page’s
user interface through a layer of objects called server controls.
Trang 37Next, you’ll explore the fundamentals of ASP.NET programming Chapter 7 presentsdifferent techniques for handling errors, and Chapter 8 introduces some of the mostremarkable ASP.NET controls, such as the input validators Chapter 9 describes differentstrategies for state management Chapter 10 shows how you can standardize theappearance of an entire website with master pages, and Chapter 11 shows you how toadd navigation to a website Finally, Chapter 12 walks you through the steps for deploy-ing your application to a web server Taken together, these chapters contain all the coreconcepts you need to design web pages and create a basic ASP.NET website.
Part 3: Working with Data
Almost all software needs to work with data, and web applications are no exception InChapter 13, you begin exploring the world of data by considering ADO.NET—Microsoft’snew technology for interacting with relational databases Chapters 14 and 15 explain how
to use data binding and the advanced ASP.NET data controls to create web pages thatintegrate attractive, customizable data displays with automatic support for paging, sorting,and editing
Chapter 16 moves out of the database world and considers how to interact with files.Chapter 17 broadens the picture even further and describes how ASP.NET applicationscan use the XML support that’s built into the NET Framework
Part 4: Website Security
Every public website needs to deal with security—making sure that sensitive data cannot
be accessed by the wrong users In Chapter 18, you’ll start out learning how ASP.NETprovides different authentication systems for dealing with users You can write your owncustom logic to verify user names and passwords, or you can use existing Windows accountinformation on your web server In Chapter 19, you’ll learn about a new model that extendsthe basic authentication system with prebuilt security controls and objects that automatecommon tasks If you want, you can even get ASP.NET to create and manage a databasewith user information automatically Finally, Chapter 20 deals with another add-on—theprofiles model that lets you store information for each user automatically, without writingany database code
Part 5: Web Services
Web services are a new feature of ASP.NET and are one of Microsoft’s most heavily promotednew technologies Using web services, you can share pieces of functionality on your webserver with other applications on other computers Best of all, the whole process workswith open standards such as XML, ensuring that applications written in different program-ming languages and running on different operating systems can interact without a hitch
Trang 38Chapter 21 presents an overview of web service technology Chapter 22 shows how tocreate a basic web service and use it in a client Chapter 23 shows you how to enhance
your web service with caching, security, and transactions
Part 6: Advanced ASP.NET
This part includes the advanced topics you can use to take your web applications that
extra step Chapters 24 and 25 cover how you can create reusable components and web
controls for ASP.NET applications Chapter 26 demonstrates how careful use of caching
can boost the performance of almost any web application
Feedback
This book has the ambitious goal of being the best tutorial and reference for ASP.NET
Toward that end, your comments and suggestions are extremely helpful You can send
complaints, adulation, and everything in between directly to apress@prosetech.com I can’t
solve your ASP.NET problems or critique your code, but I do benefit from information about
what this book did right and wrong (and what it may have done in an utterly confusing
way) You can also send comments about the website support for this book
Trang 40Introducing NET
P A R T 1
■ ■ ■