Sinh vienit.net --training kit web-based

9,740 views
9,483 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
9,740
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Sinh vienit.net --training kit web-based

  1. 1. PUBLISHED BYMicrosoft PressA Division of Microsoft CorporationOne Microsoft WayRedmond, Washington 98052-6399Copyright © 2007 by Glenn Johnson and Tony NorthrupAll rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or byany means without the written permission of the publisher.Library of Congress Control Number 2006932076ISBN-13: 978-0-7356-2334-7ISBN-10: 0-7356-2334-1Printed and bound in the United States of America.1 2 3 4 5 6 7 8 9 QWT 1 0 9 8 7 6Distributed in Canada by H.B. Fenn and Company Ltd.A CIP catalogue record for this book is available from the British Library.Microsoft Press books are available through booksellers and distributors worldwide. For further informationabout international editions, contact your local Microsoft Corporation office or contact Microsoft Press International directly at fax (425) 936-7329. Visit our Web site at www.microsoft.com/mspress. Send commentsto tkinput@microsoft.com.Microsoft, Active Directory, Internet Explorer, MSDN, MSN, PGR, Segoe, Visual Basic, Visual Studio, VisualWeb Developer, Windows, and Windows Server are either registered trademarks or trademarks of MicrosoftCorporation in the United States and/or other countries. Other product and company names mentioned hereinmay be the trademarks of their respective owners.The example companies, organizations, products, domain names, e-mail addresses, logos, people, places, andevents depicted herein are fictitious. No association with any real company, organization, product, domainname, e-mail address, logo, person, place, or event is intended or should be inferred.This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers,or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectlyby this book.Acquisitions Editor: Ken JonesProject Editor: Jenny Moss BensonEditorial Production: nSight, Inc.Copy Editor: Evan GelderTechnical Reviewer: Thomas KeeganIndexer: Nancy GuentherBody Part No. X12-48741
  2. 2. DedicationFor Chris Geggis —Tony Northrup
  3. 3. About the Authors Glenn Johnson Glenn Johnson is a professional trainer, consultant, and developer whose experience spans the past 20 years. As a consultant and developer, he has worked on several large projects, the latest being a successful conversion of a SmallTalk/GemStone system to C#/ Microsoft SQL Server for a very large customer. This is Glenn’s third .NET-related book, and he has also developed courseware for and taught classes in many countries on Microsoft ASP.NET, Visual Basic .NET, C#, and the .NET Framework. Glenn holds the following Microsoft Certifications: MCT, MCPD, MCTS, MCAD, MCSD, MCDBA, MCP + Site Building, MCSE + Internet, MCP + Internet, and MCSE. You can find Glenn’s Web site at http://GJTT.com. Tony Northrup Tony Northrup, MCTS, MCSE, CISSP, and Microsoft MVP, is a consultant and author. He has written more than a dozen books covering Windows networking, security, and develop­ ment. Among other titles, Tony is coauthor of the MCSA/MCSE Self-Paced Training Kits for Exams 70-536 and 70-330/340. When he’s not consulting or writing, Tony enjoys cycling, hik­ ing, and nature photography. Tony lives in Phillipston, Massa­ chusetts, with his wife, Erica, his cat, Sam, and his dog, Sandi. You can learn more about Tony by visiting his Web site at http://www.northrup.org.
  4. 4. Contents at a Glance1 Introducing the ASP.NET 2.0 Web Site . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Adding and Configuring Server Controls. . . . . . . . . . . . . . . . . . . . . . . . . . 513 Exploring Specialized Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . 954 Using ADO.NET and XML with ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . 2255 Creating Custom Web Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3896 Input Validation and Site Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4617 ASP.NET State Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4978 Programming the Web Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5379 Customizing and Personalizing a Web Application . . . . . . . . . . . . . . . . 58110 Globalization and Accessibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64911 Implementing Authentication and Authorization . . . . . . . . . . . . . . . . . 68112 Creating ASP.NET Mobile Web Applications . . . . . . . . . . . . . . . . . . . . . . 72713 Monitoring, Deploying, and Caching Applications . . . . . . . . . . . . . . . . 761 vii
  5. 5. Table of Contents Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii Hardware Requirements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii Software Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxviii Using the CD and DVD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxviii How to Install the Practice Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxix How to Use the Practice Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxix How to Uninstall the Practice Tests. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxi How to Install the Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxi Microsoft Certified Professional Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxi Technical Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxii Evaluation Edition Software Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxii1 Introducing the ASP.NET 2.0 Web Site . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Before You Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Lesson 1: Understanding the Players . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 The Web Server’s Role . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 The Web Browser’s Role . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Understanding Hypertext Transfer Protocol’s Role . . . . . . . . . . . . . . . . . . . . . . . . 5 Lab: Exploring HTTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Lesson Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Lesson 2: Creating a Web Site and Adding New Web Pages . . . . . . . . . . . . . . . . . . . 17 Understanding the Visual Studio 2005 Web Site Types . . . . . . . . . . . . . . . . . . . 17 The Visual Studio 2005 Solution Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Looking at the ASP.NET Page Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 In-Line versus Code-Behind Programming Model . . . . . . . . . . . . . . . . . . . . . . . 19 Dynamic Web Site Compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Creating a Web Site . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Microsoft is interested in hearing your feedback about this publication so we can What do you think of this book? continually improve our books and learning resources for you. To participate in a brief We want to hear from you! online survey, please visit: www.microsoft.com/learning/booksurvey/ ix
  6. 6. x Contents What’s in the Newly Created Web Site? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Adding New Web Pages to the Web Site. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Lab: Create a New Web Site . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Lesson Review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Lesson 3: Working with Web Configuration Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Processing the Configuration Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Modifying the Configuration Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Lab: Modifying Your Web Site Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Lesson Review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Lesson 4: Using ASP.NET Trace to Explore Web Pages . . . . . . . . . . . . . . . . . . . . . . . . . 37 Enabling and Configuring the ASP.NET Trace Facility. . . . . . . . . . . . . . . . . . . . . . 37 Viewing the Trace Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Lab: Using the ASP.NET Trace Facility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Lesson Review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Case Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Case Scenario 1: Creating a New Web Site . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Case Scenario 2: Placing Files in the Proper Folders . . . . . . . . . . . . . . . . . . . . . . 47 Suggested Practices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Create a New Web Site Using Visual Studio 2005 . . . . . . . . . . . . . . . . . . . . . . . . 48 Add a Web Page to the Web Site . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Program a Web Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Configure Settings for a Web Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Optimize and Troubleshoot a Web Application . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Take a Practice Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
  7. 7. Contents xi2 Adding and Configuring Server Controls. . . . . . . . . . . . . . . . . . . . . . . . . . 51 Before You Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Lesson 1: Using a Server Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Understanding the Life Cycle of the Web Page and Its Controls. . . . . . . . . . . . 54 Making the Decision: HTML or Web Server Controls? . . . . . . . . . . . . . . . . . . . . 60 HTML Server Controls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Web Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Adding Web Server Controls to the Web Page . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Adding Web Server Controls Using Design View. . . . . . . . . . . . . . . . . . . . . . . . . 69 Adding Web Server Controls Using Source View . . . . . . . . . . . . . . . . . . . . . . . . . 69 Adding Web Server Controls Dynamically Via Code . . . . . . . . . . . . . . . . . . . . . . 69 Lab: Exploring Web Page and Server Control Life Cycle Events . . . . . . . . . . . . 76 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Lesson Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 Lesson 2: Exploring Common Web Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 The Label Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 The TextBox Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 The Button Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 The CheckBox Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 The RadioButton Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 Lab: Working With Web Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Lesson Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Case Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 Case Scenario 1: Determining the Type of Controls to Use . . . . . . . . . . . . . . . . 92 Case Scenario 2: Selecting the Proper Events to Use . . . . . . . . . . . . . . . . . . . . . 92 Suggested Practices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
  8. 8. xii Contents Create a New Web Page Using Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . 92 Create Event Handlers for Pages and Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 Program a Web Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 Take a Practice Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 3 Exploring Specialized Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Before You Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Lesson 1: Exploring Specialized Web Server Controls. . . . . . . . . . . . . . . . . . . . . . . . . . 98 The Literal Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 The Table, TableRow, and TableCell Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . .101 The Image Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .105 The ImageButton Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .108 The ImageMap Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .110 The Calendar Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .117 The FileUpload Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .125 The Panel Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .129 The MultiView and View Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .131 The Wizard Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .135 The Xml Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .141 Lab: Work with Specialized Web Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .146 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .153 Lesson Review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .153 Lesson 2: Working with Data-Bound Web Server Controls . . . . . . . . . . . . . . . . . . . .155 Using a Collection to Perform Data-Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . .155 Introducing Data-Bound Controls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .158 Using DataSource Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .160 Mapping Fields to Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .161 Using the DataBinder Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .162 Exploring the ListControl. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .163 The DropDownList Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .165 The ListBox Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .167 The CheckBoxList and RadioButtonList Controls . . . . . . . . . . . . . . . . . . . . . . . . .170
  9. 9. Contents xiii The BulletedList Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 The AdRotator Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 The CompositeDataBoundControl Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 The GridView Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 The DetailsView Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 The FormView Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 The HierarchicalDataBoundControl Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 The TreeView Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 The Menu Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 Lab: Use the GridView and DetailsView Controls . . . . . . . . . . . . . . . . . . . . . . . . 210 Lesson Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 Case Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 Case Scenario 1: Determining How to Prompt for Data . . . . . . . . . . . . . . . . . 222 Case Scenario 2: Implementing a Calendar Solution . . . . . . . . . . . . . . . . . . . . 222 Case Scenario 3: Implementing a Master/Detail Solution . . . . . . . . . . . . . . . . 222 Suggested Practices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 Create New Web Pages Using Each of the Server Controls . . . . . . . . . . . . . . . 223 Create a Master/Detail Solution Using the Data-Bound Server Controls. . . . 223 Modify the Appearance of a Data-Bound Control Using Templates. . . . . . . . 223 Take a Practice Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2244 Using ADO.NET and XML with ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . 225 Before You Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 Lesson 1: Using the ADO.NET Disconnected Classes . . . . . . . . . . . . . . . . . . . . . . . . . 230 Getting Started with the DataTable Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230 Using a DataSet Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 Lab: Working with Disconnected Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
  10. 10. xiv Contents Lesson Review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .278 Lesson 2: Using the ADO.NET Connected Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . .280 Using Provider Classes to Move Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .280 Asynchronous Data Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .328 Lab: Working with Connected Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .342 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .343 Lesson Review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .344 Lesson 3: Working with XML Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .346 The XML Document Object Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .346 Validating XML Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .377 Lab: Working with XML Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .381 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .382 Lesson Review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .382 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .384 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .384 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .384 Case Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .385 Case Scenario 1: Determining Ways to Update the Database . . . . . . . . . . . . .385 Case Scenario 2: Storing a DataSet to a Binary File . . . . . . . . . . . . . . . . . . . . . .385 Suggested Practices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .385 Create a New Web Page For Updating Database Data . . . . . . . . . . . . . . . . . . .386 Create a New Web Page For Editing Disconnected Data . . . . . . . . . . . . . . . . .386 Create a New Web Page For Editing Connected Data. . . . . . . . . . . . . . . . . . . .386 Create a New Web Page Working with XML Data . . . . . . . . . . . . . . . . . . . . . . .387 Create a New Web Page for Reading, Modifying, and Writing XML Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .387 Take a Practice Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .387 5 Creating Custom Web Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389 Before You Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .390 Custom Web Control Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .391 Lesson 1: Working with User Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .392
  11. 11. Contents xv Employing User Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392 Creating a User Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393 Adding a User Control to a Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394 Accessing Data from the User Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395 Positioning User Controls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398 User Control Events. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399 Dynamically Loading Controls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400 Raising Events to the Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402 Creating a Templated User Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406 Using the Templated User Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411 Lab: Working With User Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420 Lesson Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421Lesson 2: Working with Custom Web Server Controls . . . . . . . . . . . . . . . . . . . . . . . . 423 Employing Custom Web Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423 Creating a Custom Web Server Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423 Adding a Custom Web Server Control to the Toolbox . . . . . . . . . . . . . . . . . . . 429 Individualizing a Custom Web Server Control . . . . . . . . . . . . . . . . . . . . . . . . . . 430 Creating a Custom Designer for a Custom Control . . . . . . . . . . . . . . . . . . . . . . 431 Creating a Composite Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433 Creating a Templated Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439 Using the Templated Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446 Lab: Working With Custom Web Server Controls . . . . . . . . . . . . . . . . . . . . . . . 449 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454 Lesson Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454Chapter Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456Case Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457 Case Scenario 1: Sharing Controls Between Applications . . . . . . . . . . . . . . . . 457 Case Scenario 2: Providing Layout Flexibility . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
  12. 12. xvi Contents Suggested Practices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .457 Create a New Custom User Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .457 Create a New Custom Web Server Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . .458 Create a New Composite Web Server Control . . . . . . . . . . . . . . . . . . . . . . . . . .458 Create a New Templated Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .458 Take a Practice Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .459 6 Input Validation and Site Navigation. . . . . . . . . . . . . . . . . . . . . . . . . . . . 461 Before You Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .462 Lesson 1: Performing Input Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .464 Understanding the Validation Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .464 Understanding the BaseValidator Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .466 Understanding the RequiredFieldValidator Control . . . . . . . . . . . . . . . . . . . . . .467 Understanding the BaseCompareValidator Class . . . . . . . . . . . . . . . . . . . . . . . .467 Using the CompareValidator Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .468 Using the RangeValidator Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .468 Using the RegularExpressionValidator Control . . . . . . . . . . . . . . . . . . . . . . . . . .468 The CustomValidator Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .469 Ensuring Server-Side Validation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .473 Determining When to Validate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .474 Using Validation Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .474 Lab: Working with Validation Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .475 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .478 Lesson Review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .479 Lesson 2: Performing Site Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .481 Is Site Navigation Necessary?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .481 Choosing a Method to Navigate Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .481 Providing Client-Side Code or Markup to Request a New Web Page . . . . . . .482 Cross-page Posting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .483 Accessing Strongly Typed Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .484 Issuing Client-Side Browser Redirect. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .485
  13. 13. Contents xvii Issuing Server-Side Transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486 Using the Site Map Web Server Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487 Using the SiteMap Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488 Lab: Working With Site Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491 Lesson Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493 Case Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493 Case Scenario 1: Determining the Proper User Name Validators to Implement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494 Case Scenario 2: Determining the Proper Password Validators to Implement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494 Case Scenario 3: Implementing a Site Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494 Suggested Practices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494 Create a Web Site and Program Redirection. . . . . . . . . . . . . . . . . . . . . . . . . . . . 494 Create a Data Collection Page with Validation . . . . . . . . . . . . . . . . . . . . . . . . . . 495 Implement the HyperLink Web Server Control . . . . . . . . . . . . . . . . . . . . . . . . . 495 Take a Practice Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4957 ASP.NET State Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497 Before You Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498 Lesson 1: Using Client-Side State Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499 Choosing Client-Side or Server-Side State Management . . . . . . . . . . . . . . . . . 500 View State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501 Control State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504 Hidden Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505 Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505 Query Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509 Lab: Store State Management Data on the Client . . . . . . . . . . . . . . . . . . . . . . . 512 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516
  14. 14. xviii Contents Lesson Review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .517 Lesson 2: Using Server-Side State Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . .519 Application State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .519 Session State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .522 Profile Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .527 Lab: Store State Management Data on the Server . . . . . . . . . . . . . . . . . . . . . . .527 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .530 Lesson Review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .530 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .532 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .532 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .532 Case Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .533 Case Scenario 1: Remembering User Credentials. . . . . . . . . . . . . . . . . . . . . . . .533 Case Scenario 2: Analyzing Information for Individual Users and for All Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .534 Suggested Practices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .534 Manage State by Using Client-Based State Management Options . . . . . . . . .534 Manage State by Using Server-Based State Management Options . . . . . . . . .535 Maintain State by Using Database Technology . . . . . . . . . . . . . . . . . . . . . . . . . .535 Respond to Application and Session Events . . . . . . . . . . . . . . . . . . . . . . . . . . . .535 Take a Practice Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .536 8 Programming the Web Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537 Before You Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .538 Lesson 1: Using Web Site Programmability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .539 Page and Application Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . .539 Programming the Web.Config File Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . .541 Asynchronous Web Page Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .547 Dynamically Generate Images Using an ASP.NET Handler . . . . . . . . . . . . . . . .549 Lab: Creating a Custom Handler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .553 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .555 Lesson Review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .556 Lesson 2: Using Request Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .558
  15. 15. Contents xix Determining the Browser Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558 Page and Application Context Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 562 Accessing Web Page Headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569 Lab: Examine Page and Application Context . . . . . . . . . . . . . . . . . . . . . . . . . . . 570 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573 Lesson Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576 Case Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576 Case Scenario 1: Dynamically Generating Charts . . . . . . . . . . . . . . . . . . . . . . . 576 Case Scenario 2: Dynamically Adjusting Pages Based on Browser Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577 Suggested Practices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577 Program a Web Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577 Add and Configure Web Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578 Write an ASP.NET Handler to Generate Images Dynamically for Display on a Web Page. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579 Take a Practice Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5799 Customizing and Personalizing a Web Application . . . . . . . . . . . . . . . . 581 Before You Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582 Lesson 1: Using Master Pages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 584 Overview of Master and Content Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585 The Process of Creating Master and Content Pages . . . . . . . . . . . . . . . . . . . . . 588 Techniques for Attaching Content Pages to a Master Page . . . . . . . . . . . . . . . 589 Referencing Master Page Properties and Controls from Content Pages . . . . 590 Handling Events When Working with Master Pages . . . . . . . . . . . . . . . . . . . . . 592 Creating a Nested Master Page. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593 Dynamically Changing Master Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594 Lab: Using Master and Child Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599 Lesson Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 600
  16. 16. xx Contents Lesson 2: Using Themes and User Profiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .602 Using Themes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .602 Using User Profiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .609 Dynamically Adding Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .613 Lab: Applying Themes and User Profiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .614 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .619 Lesson Review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .619 Lesson 3: Using Web Parts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .621 What Are Web Parts? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .621 Adding Web Parts to a Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .623 Enabling Users to Arrange and Edit Web Parts. . . . . . . . . . . . . . . . . . . . . . . . . .623 Connecting Web Parts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .625 Personalizing Web Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .629 Lab: Using Web Parts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .631 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .640 Lesson Review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .640 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .642 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .642 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .642 Case Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .643 Case Scenario 1: Meet Customization Requirements for an Internal Insurance Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .643 Case Scenario 2: Provide Consistent Formatting for an External Web Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .644 Suggested Practices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .645 Implement a Consistent Page Design by Using Master Pages . . . . . . . . . . . .645 Customize a Web Page by Using Themes and User Profiles . . . . . . . . . . . . . . .646 Implement Web Parts in a Web Application . . . . . . . . . . . . . . . . . . . . . . . . . . . .646 Take a Practice Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .64710 Globalization and Accessibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649 Before You Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .649 Lesson 1: Configuring Globalization and Localization . . . . . . . . . . . . . . . . . . . . . . . .651
  17. 17. Contents xxi Using Resource Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651 HTML Layout Best Practices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 658 Setting the Culture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659 Lab: Creating a Web Page That Supports Multiple Cultures . . . . . . . . . . . . . . 661 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 663 Lesson Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 664 Lesson 2: Configuring Accessibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665 Public Accessibility Guidelines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665 How ASP.NET Controls Support Accessibility . . . . . . . . . . . . . . . . . . . . . . . . . . . 666 Improving Visual Accessibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 667 Improving the Accessibility of Forms Requiring User Input . . . . . . . . . . . . . . 669 Testing Accessibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 671 Lab: Improving the Accessibility of a Web Page. . . . . . . . . . . . . . . . . . . . . . . . . 672 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674 Lesson Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 676 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 676 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 677 Case Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 677 Case Scenario 1: Upgrade an Application for Multiple Languages . . . . . . . . 677 Case Scenario 2: Making a Web Application Accessible . . . . . . . . . . . . . . . . . 678 Suggested Practices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 678 Implement Globalization and Accessibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 678 Take a Practice Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67911 Implementing Authentication and Authorization . . . . . . . . . . . . . . . . . 681 Before You Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 683 Lesson 1: Using ASP.NET Membership . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 684 Login Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 684 The Membership Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 686 The Roles Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 687 Configuring Web Applications to Use ASP.NET Membership. . . . . . . . . . . . . . 688 Lab: Configuring Authentication in ASP.NET Applications . . . . . . . . . . . . . . . . 694
  18. 18. xxii Contents Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .696 Lesson Review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .697 Lesson 2: Using Windows, Forms, Passport, and Anonymous Authentication . . . .699 Configuring Web Applications to Require Windows Authentication . . . . . . .699 Creating Custom ASP.NET Forms to Authenticate Web Users . . . . . . . . . . . . .702 Configuring Web Applications to Require Passport Authentication . . . . . . . .710 Configuring Web Applications for Only Anonymous Access . . . . . . . . . . . . . .711 Configuring Impersonation by Using .config Files . . . . . . . . . . . . . . . . . . . . . . .711 Restricting Access to ASP.NET Web Applications, Files, and Folders . . . . . . . .712 Lab: Controlling Authorization in ASP.NET Applications . . . . . . . . . . . . . . . . . .715 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .717 Lesson Review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .717 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .720 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .720 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .721 Case Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .721 Case Scenario 1: Configuring Web Application Authorization . . . . . . . . . . . .721 Case Scenario 2: Configuring Web Application Authentication . . . . . . . . . . .723 Suggested Practices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .724 Establish a User’s Identity by Using Forms Authentication . . . . . . . . . . . . . . . .724 Use Authorization to Establish the Rights of an Authenticated User. . . . . . . .725 Implement Microsoft Windows Authentication and Impersonation . . . . . . . .725 Use Login Controls to Control Access to a Web Application . . . . . . . . . . . . . .726 Take a Practice Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .726 12 Creating ASP.NET Mobile Web Applications . . . . . . . . . . . . . . . . . . . . . 727 Before You Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .727 Lesson 1: Building Mobile Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .729 Introducing the Mobile Web Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .729 Creating a Mobile Web Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .729 Viewing and Testing Mobile Web Applications . . . . . . . . . . . . . . . . . . . . . . . . .730 Understanding Mobile Web Forms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .732
  19. 19. Contents xxiii Using Mobile Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 740 Applying Best Practices to Mobile Applications . . . . . . . . . . . . . . . . . . . . . . . . . 746 Lab: Working with Mobile Web Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . 747 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 754 Lesson Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 755 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 757 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 757 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 757 Case Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 757 Case Scenario 1: Determining the Mobile Control to Use . . . . . . . . . . . . . . . . 757 Case Scenario 2: Determining How Many Web Pages to Create . . . . . . . . . . 758 Suggested Practices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 758 Create a Mobile Web Application Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 758 Exploring Adaptive Rendering. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 758 Implement Device-Specific Rendering. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 759 Create a Data-Collection Page with Validation. . . . . . . . . . . . . . . . . . . . . . . . . . 759 Take a Practice Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76013 Monitoring, Deploying, and Caching Applications . . . . . . . . . . . . . . . . 761 Before You Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 762 Lesson 1: Deploying Web Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763 Using Web Setup Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763 Deploying Web Applications Using the Copy Web Tool. . . . . . . . . . . . . . . . . . 778 Precompiling Web Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 781 Lab: Deploying Web Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 782 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 785 Lesson Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 786 Lesson 2: Building Web Applications for Monitoring . . . . . . . . . . . . . . . . . . . . . . . . 788 Customizing Event Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 788 Providing Custom Performance Counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 795 Lab: Monitoring Web Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 799 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 803
  20. 20. xxiv Contents Lesson Review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .803 Lesson 3: Using Caching to Improve Performance . . . . . . . . . . . . . . . . . . . . . . . . . . .805 Application Caching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .806 Page Output Caching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .809 Lab: Using Page Output Caching to Improve Performance . . . . . . . . . . . . . . .817 Lesson Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .818 Lesson Review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .819 Chapter Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .821 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .821 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .822 Case Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .822 Case Scenario 1: Deploying a Web Application . . . . . . . . . . . . . . . . . . . . . . . . .822 Case Scenario 2: Improving the Performance of a Public Web Site . . . . . . . .823 Suggested Practices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .824 Use a Web Setup Project to Deploy a Web Application to a Target Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .824 Copy a Web Application to a Target Server by Using the Copy Web Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .824 Precompile a Web Application by Using the Publish Web Utility . . . . . . . . . .825 Optimize and Troubleshoot a Web Application . . . . . . . . . . . . . . . . . . . . . . . . .825 Take a Practice Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .826Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .827Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .867Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .873 Microsoft is interested in hearing your feedback about this publication so we can What do you think of this book? continually improve our books and learning resources for you. To participate in a brief We want to hear from you! online survey, please visit: www.microsoft.com/learning/booksurvey/
  21. 21. Acknowledgments Glenn Johnson To Jenny Moss Benson, thanks for your constructive feedback throughout the entire process of writing this book. Thanks for also having patience while the summer months were passing and my desire to play outweighed my desire to write. Thanks to Ken Jones for persuading me to have a co-author on this book. Tony Northrup, thanks for being a wonderful co-author, and thanks for your profes­ sionalism during all stages of writing this book. To everyone at Microsoft Press who has played a role in getting this book to the public, thank you for your hard work and thanks for making this book venture a positive experience for me. Tony Northrup Many people helped me with this book by distracting me at the right times. My friends and family, especially Tara, John, and Emilie Banks; Kristin Casciato; Bob and Heather Dean; Mike, Michelle, Ray, and Sandi Edson; Chris and Diane Geggis; Bob Hogan; Sam Jackson; Tom and Heather Keegan; Kim Lively; Jenny Lozier; Eric and Ali­ son Parucki; Skip and Chris Rice; Scott and Debbie Robichaud; Carol Whitney; and Jimmy and Gloria Young helped me enjoy my time away from the keyboard. More than anyone, I have to thank my wife, Erica, for being so patient during many long days of writing. xxv
  22. 22. Introduction This training kit is designed for developers who plan to take Microsoft Certified Technical Specialist (MCTS) exam 70-528, as well as for developers who need to know how to develop applications using the Microsoft .NET Framework 2.0. We assume that before you begin using this kit, you have a working knowledge of Microsoft Windows and Microsoft Visual Basic or C#. By using this training kit, you’ll see how to do the following: ■ Create a Web application using Web server controls, event handlers, application state, and session state. ■ Create custom Web server controls. ■ Develop accessible Web applications that can be used by a global audience. ■ Integrate a Web application with a back-end database. ■ Create a Web application that stores user-specific information and preferences. ■ Add authentication and authorization features to your application to improve security and add multiple access levels. ■ Create Web applications that can be used from mobile phones and PDAs.Hardware Requirements The following hardware is required to complete the practice exercises: ■ Computer with a 600 MHz or faster processor ■ 192 MB of RAM or more ■ 2 GB of available hard disk space ■ DVD-ROM drive ■ 1,024 x 768 or higher resolution display with 256 colors ■ Keyboard and Microsoft mouse, or compatible pointing device xxvii
  23. 23. xxviii IntroductionSoftware Requirements The following software is required to complete the practice exercises: ■ One of the following operating systems: ❑ Microsoft Windows 2000 with Service Pack 4 ❑ Microsoft Windows XP with Service Pack 2 ❑ Microsoft Windows XP Professional x64 Edition (WOW) ❑ Microsoft Windows Server 2003 with Service Pack 1 ❑ Microsoft Windows Server 2003, x64 Editions (WOW) ❑ Microsoft Windows Server 2003 R2 ❑ Microsoft Windows Server 2003 R2, x64 Editions (WOW) ❑ Microsoft Windows Vista ■ Microsoft Visual Studio 2005 (A 90-day evaluation edition of Visual Studio 2005 Professional Edition is included on DVD with this book.)Using the CD and DVD A companion CD and an evaluation software DVD are included with this training kit. The companion CD contains the following: ■ Practice tests You can reinforce your understanding of how to create .NET Framework 2.0 applications by using electronic practice tests that you customize to meet your needs from the pool of Lesson Review questions in this book. Or, you can practice for the 70-528 certification exam by using tests created from a pool of 300 realistic exam questions, which is enough to give you many different practice exams to ensure that you’re prepared. ■ Code Most chapters in this book include sample files associated with the lab exercises at the end of every lesson. For some exercises, you will be instructed to open a project prior to starting the exercise. For other exercises, you will create a project on your own and be able to reference a completed project in the event you experience a problem following the exercise. ■ An eBook An electronic version (eBook) of this book is included for times when you don’t want to carry the printed book with you. The eBook is in Portable Doc­ ument Format (PDF); you can view it by using Adobe Acrobat or Adobe Reader.
  24. 24. Introduction xxix The evaluation software DVD contains a 90-day evaluation edition of Visual Studio 2005 Professional Edition, in case you want to use it with this book.How to Install the Practice Tests To install the practice test software from the companion CD to your hard disk, do the following: 1. Insert the companion CD into your CD drive, and accept the license agreement. A CD menu appears. NOTE If the CD menu doesn’t appear If the CD menu or the license agreement doesn’t appear, AutoRun might be disabled on your computer. Refer to the Readme.txt file on the CD-ROM for alternate installation instructions. 2. Click the Practice Tests item, and follow the instructions on the screen.How to Use the Practice Tests To start the practice test software, follow these steps: 1. Click Start | All Programs | Microsoft Press Training Kit Exam Prep. A window appears that shows all the Microsoft Press training kit exam prep suites installed on your computer. 2. Double-click the lesson review or practice test that you want to use. NOTE Lesson reviews vs. practice tests Select the (70-528) Microsoft .NET Framework 2.0—Web-Based Client Development lesson review to use the questions from the “Lesson Review” sections of this book. Select the (70-528) Microsoft .NET Framework 2.0 — Web-Based Client Development practice test to use a pool of 300 questions similar to those in the 70-528 certification exam. Lesson Review Options When you start a lesson review, the Custom Mode dialog box appears so that you can configure your test. You can click OK to accept the defaults, or you can customize the number of questions you want, how the practice test software works, which exam objectives you want the questions to relate to, and whether you want your lesson review to be timed. If you’re retaking a test, you can select whether you want to see all the questions again or only those questions you missed or didn’t answer.
  25. 25. xxx Introduction After you click OK, your lesson review starts. ■ To take the test, answer the questions and use the Next, Previous, and Go To but­ tons to move from question to question. ■ After you answer an individual question, if you want to see which answers are correct—along with an explanation of each correct answer—click Explanation. ■ If you’d rather wait until the end of the test to see how you did, answer all the questions, and then click Score Test. You’ll see a summary of the exam objectives you chose and the percentage of questions you got right overall and per objec­ tive. You can print a copy of your test, review your answers, or retake the test. Practice Test Options When you start a practice test, you choose whether to take the test in Certification Mode, Study Mode, or Custom Mode: ■ Certification Mode Closely resembles the experience of taking a certification exam. The test has a set number of questions, it’s timed, and you can’t pause and restart the timer. ■ Study Mode Creates an untimed test in which you can review the correct answers and the explanations after you answer each question. ■ Custom Mode Gives you full control over the test options so that you can cus­ tomize them as you like. In all modes, the user interface you see when taking the test is the basically the same, but with different options enabled or disabled depending on the mode. The main options are discussed in the previous section, “Lesson Review Options.” When you review your answer to an individual practice test question, a “References” section is provided that lists where in the training kit you can find the information that relates to that question; it also provides links to other sources of information. After you click Test Results to score your entire practice test, you can click the Learn­ ing Plan tab to see a list of references for every objective.
  26. 26. Introduction xxxiHow to Uninstall the Practice Tests To uninstall the practice test software for a training kit, use the Add Or Remove Pro­ grams option in Windows Control Panel.How to Install the Code To install the sample files referenced in the book’s exercises from the companion CD to your hard disk, do the following: 1. Insert the companion CD into your CD drive, and accept the license agreement. A CD menu appears. NOTE If the CD menu doesn’t appear If the CD menu or the license agreement doesn’t appear, AutoRun might be disabled on your computer. Refer to the Readme.txt file on the CD-ROM for alternate installation instructions. 2. Click the Code item, and follow the instructions on the screen. The code will be installed to Documents and Settings<user>My Documents MicrosoftPress70-528.Microsoft Certified Professional Program The Microsoft certifications provide the best method to prove your command of cur­ rent Microsoft products and technologies. The exams and corresponding certifica­ tions are developed to validate your mastery of critical competencies as you design and develop, or implement and support, solutions with Microsoft products and tech­ nologies. Computer professionals who become Microsoft-certified are recognized as experts and are sought after industry-wide. Certification brings a variety of benefits to the individual and to employers and organizations. MORE INFO All the Microsoft certifications For a full list of Microsoft certifications, go to http://www.microsoft.com/learning/mcp/default.asp.
  27. 27. xxxii IntroductionTechnical Support Every effort has been made to ensure the accuracy of this book and the contents of the companion CD. If you have comments, questions, or ideas regarding this book or the companion CD, please send them to Microsoft Press by using either of the following methods: E-mail: tkinput@microsoft.com Postal Mail: Microsoft Press Attn: MCTS Self-Paced Training Kit (Exam 70-528): Microsoft .NET Framework 2.0 - Web- Based Client Development Editor One Microsoft Way Redmond, WA 98052–6399 For additional support information regarding this book and the CD-ROM (includ­ ing answers to commonly asked questions about installation and use), visit the Microsoft Press Technical Support website at http://www.microsoft.com/learning/ support/books/. To connect directly to the Microsoft Knowledge Base and enter a query, visit http://support.microsoft.com/search/. For support information regard­ ing Microsoft software, please connect to http://support.microsoft.com.Evaluation Edition Software Support The 90-day evaluation edition provided with this training kit is not the full retail prod­ uct and is provided only for the purposes of training and evaluation. Microsoft and Microsoft Technical Support do not support this evaluation edition. Information about any issues relating to the use of this evaluation edition with this training kit is posted to the Support section of the Microsoft Press Web site (http:// www.microsoft.com/learning/support/books/). For information about ordering the full version of any Microsoft software, please call Microsoft Sales at (800) 426-9400 or visit http://www.microsoft.com.
  28. 28. Chapter 1Introducing the ASP.NET 2.0 WebSite Microsoft Visual Studio 2005 and ASP.NET 2.0 represent a major release for Microsoft. If you have previous experience with Visual Studio products, you will see the differences immediately when you attempt to create your first Web site. Even if you are new to Visual Studio 2005 and ASP.NET 2.0, you will be able to immediately take advantage of the productivity enhancements. This chapter starts by introducing the Web site players (Web server, Web browser, and Hypertext Transfer Protocol [HTTP]). It explores the architecture of an ASP.NET Web site and then shows the various ways that you can create a Web site. After that, you will learn about some of the Web site configuration options in Visual Studio 2005. Exam objectives in this chapter: ■ Program a Web application. ❑ Avoid performing unnecessary processing on a round trip by using a page’s IsPostBack property. ■ Create and configure a Web application. ❑ Create a new Web application. ❑ Add Web Forms pages to a Web application. ■ Configure settings for a Web application. ❑ Configure system-wide settings in the Machine.config file. ❑ Configure settings for a Web application in the application’s Web.config file. ❑ Manage a Web application’s configuration by using the Web Site Adminis­ tration Tool. ■ Optimize and troubleshoot a Web application. ❑ Troubleshoot a Web application by using ASP.NET Trace. 1
  29. 29. 2 Chapter 1 Introducing the ASP.NET 2.0 Web Site Lessons in this chapter: ■ Lesson 1: Understanding the Players . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 ■ Lesson 2: Creating a Web Site and Adding New Web Pages . . . . . . . . . . . . . . . 17 ■ Lesson 3: Working with Web Configuration Files . . . . . . . . . . . . . . . . . . . . . . . 31 ■ Lesson 4: Using ASP.NET Trace to Explore Web Pages . . . . . . . . . . . . . . . . . . . 37Before You Begin To complete this chapter, you must: ■ Be familiar with Microsoft Visual Basic or C#. ■ Have Microsoft Windows XP, Internet Information Services (IIS) 5.1, and Visual Studio 2005 installed with Microsoft SQL Server 2005 Express Edition. ■ Be familiar with the Visual Studio 2005 Integrated Development Environment (IDE). ■ Understand how to make assemblies available to other applications. ■ Have a basic understanding of Hypertext Markup Language (HTML) and client- side scripting. Real World Glenn Johnson It’s easier to learn how to develop Web clients once you understand who the players are. I have seen many people attempt to learn Web development without learning the roles of the Web browser, HTTP, and the Web server. It’s not a pretty sight.
  30. 30. Lesson 1: Understanding the Players 3Lesson 1: Understanding the Players It’s important to get an understanding of the roles of the Web server, Web browser, and HTTP before starting your Web development. The typical communication pro­ cess can be generalized into the following steps: 1. The Web browser initiates a request for a Web server resource. 2. HTTP is used to send the GET request to the Web server. 3. The Web server processes the request. 4. The Web server sends a response to the Web browser. HTTP protocol is used to send the HTTP response to the Web browser. 5. The Web browser processes the response, displaying the Web page. 6. The user enters data and performs an action, such as clicking a Submit button that causes the data to be sent back to the Web server. 7. HTTP is used to POST the data back to the server. 8. The Web server processes the data. 9. The Web server sends the response back to the Web browser. 10. HTTP is used to send the HTTP response to the Web browser. 11. The Web browser processes the response, displaying the Web page. This section gives a brief description of how the Web browser exchanges communica­ tions with the Web server via HTTP. It also describes the responsibilities of both the Web browser and Web server. After this lesson, you will be able to: ■ Describe the Web server’s role in responding to requests for resources. ■ Describe the Web browser’s role in collecting and presenting data to the user. ■ Describe HTTP’s role in communicating to the Web server. ■ Describe how HTTP verbs are used to request resources from the Web server. ■ Describe the status-code groups that are implemented in HTTP. ■ Describe Distribute Authoring and Versioning. ■ Describe PostBack, the common method of sending data to the Web server. ■ Describe some methods for troubleshooting HTTP. Estimated lesson time: 30 minutes
  31. 31. 4 Chapter 1 Introducing the ASP.NET 2.0 Web SiteThe Web Server’s Role Let’s start with the Web server. The original Web servers were responsible for receiving and handling requests from the browsers via HTTP. Each Web server handled the request and sent a response back to the Web browser. After that, the Web server closed the connection and released all resources that were involved in the request. All resources were released because the Web server needed to be able to handle thou­ sands of requests per minute, and the original Web pages were simple, static HTML pages. The Web environment was considered to be “stateless” because no data was held at the Web server between Web browser requests, and because the connection was closed after the response was sent (see Figure 1-1). Web Browser Web Server Client initiates communications with page request GET Default.html 1. Process request Display Page 2. Send response Server responds and close the with page connection Figure 1-1 A simple request/response between Web browser and Web server in a stateless environment. Today’s Web servers deliver services that go far beyond the original Web servers. In addition to serving static HTML files, the Web servers can also handle requests for pages that contain code that will execute at the server; the Web servers will respond with the results of code execution, as shown in Figure 1-2. Web servers also have the ability to store data across Web page requests, which means that Web pages can be connected to form Web applications. Because many Web sites are set up as Web appli­ cations containing many Web pages, the idea of a Web server delivering a single page to the Web browser and closing the connection is rather outdated. Web servers now implement “keep alive” features for connections that make the Web servers keep the connections to the Web browsers open for a period of time with anticipation of addi­ tional page requests from a Web browser.
  32. 32. Lesson 1: Understanding the Players 5 Web Browser Web Server Client initiates communications with page request GET Default.aspx 1. Process request 2. Execute server-side code 3. Store session data e.g., CustomerId=5234 Display Page 4. Send result response Server responds with page Figure 1-2 Web servers now store state between page requests to enable the creation of Web applications.The Web Browser’s Role The Web browser provides a platform-independent means of displaying Web pages that were written with HTML. Platform-independent means that HTML was designed to be able to render within any operating system while placing no constraint on the window size. HTML was designed to “flow,” wrapping text as necessary to fit into the browser window. The Web browser also needs to display images and respond to hyperlinks. Each Web page request to the Web server results in the Web browser clearing the browser screen and displaying the new Web page. Although the Web browser’s role is simply to present data and collect data, many new client-side technologies enable today’s Web browsers to execute code such as Java- Script and to support plug-ins which improve the user’s experience. Technologies such as Asynchronous JavaScript and XML (AJAX) allow the Web browsers to talk to the Web servers without clearing the existing Web pages from the browser window. These technologies make the user experience much better and more robust than the user experience provided by the original Web browsers.Understanding Hypertext Transfer Protocol’s Role HTTP is a text-based communication protocol that is used to request Web pages from the Web server and send responses back to the Web browser. HTTP messages are
  33. 33. 6 Chapter 1 Introducing the ASP.NET 2.0 Web Site typically sent between the Web server and Web browser using port 80, or, when using secure HTTP (HTTPS), port 443. MORE INFO HTTP/1.1 Specification For more information on HTTP/1.1, see the HTTP/1.1 specification at http://www.w3.org/Protocols/ rfc2616/rfc2616.html. When a Web page is requested, a textual command like the following is sent to the Web server: GET /default.aspx HTTP/1.1 Host: www.northwindtraders.com Notice that the first line contains the method, also known as a verb or a command, called GET, and is followed by the Uniform Resource Locator (URL) of the Web page to be retrieved, which is followed by an indicator of the HTTP version to be used. The method indicates what action is to be performed by the Web server using the URL that follows the method. Table 1-1 contains a list of some of the common HTTP meth­ ods with a description of their uses. Note that, if Distributed Authoring and Versioning (DAV) is enabled on the Web site, many more verbs will be available, such as LOCK and UNLOCK. The second line identifies the name of the host that may be used by the Web server if the Web server is hosting more than one Web site. This process is known as using host headers to identify the Web site that will handle the request(s). Table 1-1 Common HTTP/1.1 Methods HTTP Description Method OPTIONS Used by client applications to request a lists of all supported verbs. Checks to see if a server allows a particular verb before wasting net­ work bandwidth trying to send an unsupported request. GET Gets a URL from the server. A GET request for a specific URL, say, /test.htm, retrieves the test.htm file. Data retrieved using this verb is typically cached by the browser. GET also works with collections, such as those in directories that contain collections of files. If you request a directory, the server can be configured to return a default file, such as index.html, that may be representative of the directory.
  34. 34. Lesson 1: Understanding the Players 7Table 1-1 Common HTTP/1.1 Methods HTTP Description Method HEAD Retrieves the meta information for a resource. This information is typ­ ically identical to the meta information sent in response to a GET request, but the HEAD verb never returns the actual resource. The meta information is cacheable. POST Used to create a new, dynamically named resource. Data retrieved using this verb is typically not cached. PUT Allows a client to directly create a resource at the indicated URL on the server. The server takes the body of the request, creates the file specified in the URL, and copies the received data to the newly cre­ ated file. If the file exists and is not locked, the content of the file will be overwritten. DELETE Used to delete a resource at the Web server. Requires write permis­ sions on the directory. TRACE Used for testing or diagnostics; allows the client to see what is being received at the other end of the request chain. Responses to this method are never cached. CONNECT Reserved for use with a proxy that can dynamically switch to being a tunnel, such as Secure Socket Layer (SSL) protocol. DEBUG Is not defined in the HTTP/1.1 specification, but is used to start ASP.NET debugging. Informs Visual Studio 2005 of the process that the debugger will attach to.Notice that Web-browser-to-Web-server communication is referred to as a request. InASP.NET, the Request object represents the Web browser’s communications to theWeb server asking for a resource. What Is Distributed Authoring and Versioning? Distributed Authoring and Versioning (DAV) is a set of extensions to HTTP/1.1 that simplifies Web site development when working in a team scenario. DAV is an open standard and is available on numerous platforms. DAV provides the ability to lock and unlock files plus the ability to designate versions.
  35. 35. 8 Chapter 1 Introducing the ASP.NET 2.0 Web Site DAV is built directly on HTTP/1.1, so no other protocols, such as File Transfer Pro­ tocol (FTP) or Server Message Block (SMB), are required. DAV also provides the ability to query the Web server for various resource properties such as file names, time stamps, and sizes. DAV also gives the developers the ability to perform server-side file copying and moving. For example, you can use the HTTP GET and PUT verbs to retrieve files from the Web servers and save them to different loca­ tions, or you can use the DAV’s COPY verb to simply tell a server to copy the file. The communication from the Web server back to the Web browser is commonly referred to as the response. In ASP.NET this is represented as the Response object. When the Web server responds to a request, the communication is typically in the fol­ lowing text-based format: HTTP/1.1 200 OK Server: Microsoft-IIS/6.0 Content-Type: text/html Content-Length: 38 <html><body>Hello, world.</body><html> The first line contains the protocol and version information, plus a status-code and reason. The three-digit status codes are grouped as shown in Table 1-2. Exam Tip Even if you don’t memorize every status code, it’s helpful to know the five status- code groupings in Table 1-2. Table 1-2 Status-Code Groups Status-Code Description Group 1xx Informational: Request received, continuing to process. 2xx Success: The action was successfully received, understood, and accepted. 3xx Redirect Command: Further action must be taken in order to com­ plete the request. 4xx Client Error: The request has a syntax error or the server does not know how to fulfill the request. 5xx Server Error: The server failed to fulfill a request that appears to be valid.

×