ebook img

Pro ASP.NET 2.0 in VB 2005 PDF

1358 Pages·2006·23.398 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Pro ASP.NET 2.0 in VB 2005

CYAN YELLOW MAGENTA BLACK PANTONE 123 CV BOOKS FOR PROFESSIONALS BY PROFESSIONALS® SPECIAL EDITION FULLY UPDATEDAND EXPANDEDWITH TWO NEW CHAPTERS: “JavaScript™ and Ajax”and“Atlas” Companion eBook Available Pro ASP.NET 2.0 in VB 2005 Pro THE EXPERT’S VOICE® IN.NET SPECIAL EDITION BBoonnuuss CCDD iinncclluuddeess aa ffrreeee AASSPPTTooddaayy..ccoomm eeBBooookk——mmoorree Dear Reader, i A tthhaann 660000 ppaaggeess——vvaalluueedd aatt $$2255!! Welcome to Pro ASP.NET 2.0 in VB 2005,Special Edition. This book is all about n Laurence Moroney, ASP.NET 2.0 and how you can make it work for you. It’s not a language reference Pro author of but a volume of hard-won, practical, usable advice that you can use to build V Foundations of WPF sophisticated, scalable, secure, and reliable web applications, services, and S Foundations of Atlas sites. The new features in the language and API are clearly identified for you— Pro ASP.NET 2.0 in VB 2005 so if you are coming from an earlier version of ASP.NET, you’ll not only sail B through the basics but you’ll also get a great refresher in what you already know. Pro ASP.NET 1.1 in VB .NET P Should you want to, you can go straight to the important changes and get into ASP.NET 2.0 coauthor of them as quickly as possible. Expert Web Services Because this is a Proedition, you will learn about some advanced topics that . Security in the .NET Platform you may not have access to elsewhere, such as control creation, image handling, 2 N and encryption, amongst others. In addition, this special edition contains two new chapters that get you ready for Web 2.0; these chapters cover Ajax and Atlas, which is the new toolkit 0 from Microsoft that allows you to build Ajax applications using the ASP.NET paradigm. E VB 2005 0 For this special edition of the book, we’ve also included a bonus CD contain- ing a host of valuable extras to help you really master the technology: in • A carefully selected library of chapters from 18 other Apress Proand Expert T 5 books designed to complement this book and broaden your knowledge of Matthew MacDonald, author of ASP.NET 2.0, C# 2005, VB 2005, and SQL Server 2005. That’s more than 2,000 Pro ASP.NET 2.0 in C# 2005 information-rich pages in eBook form, all fully supported with code Beginning ASP.NET 1.1 in C# samples on the Apress website. Microsoft .NET Distributed • An ASPToday.com on ASP.NET 2.0eBook, which contains 33 articles and 2 Applications over 600 pages covering ASP.NET 2.0 and SQL Server 2005 from Apress’s ASP.NET:The Complete ASPToday website. ASPToday specializes in publishing quality articles for Reference ASP developers. This is the first time this material is being made available . Create next-generation web applications with the latest coauthor of in eBook form. version of Microsoft’s revolutionary technology. Programming .NET • A full selection of our .NET 2.0 road maps that illustrate how you, the 0 Web Services reader, can link Apress books to create your own custom-made learning curve that helps you master the technology areas you need to know. Companion eBook So pin your ears back, and get ready for a wonderful ride! Laurence Moroney SPECIAL EDITION See last page for details SOURCECODEONLINE on $10 eBook version www.asptoday.com BONUSCD INCLUDED www.apress.com Laurence Moroney ISBN 1-59059-776-1 Matthew MacDonald (Ed.) and 56499 Moroney, MacDonald US $64.99 Shelve in Programming/ Bonus CDcontains an additional 2,000 pages of high-quality content from Microsoft/ASP.NET 18 Apress ASP.NET 2.0,C# 2005,VB 2005,SQL Server 2005,and Visual User level: Studio 2005 titles. Intermediate–Advanced 6 89253 59776 7 9 781590 597767 this print for content only—size & color not accurate 7" x 9-1/4" / CASEBOUND / MALLOY (2.0625 INCH BULK -- 1360 pages -- 40# Thor) 7761FM.qxd 9/5/06 8:50 AM Page i Pro ASP.NET 2.0 in VB 2005 Special Edition Laurence Moroney and Matthew MacDonald (Ed.) 7761FM.qxd 9/5/06 8:50 AM Page ii Pro ASP.NET 2.0 in VB 2005,Special Edition Copyright © 2006 by Laurence Moroney,Matthew MacDonald (Ed.),K.Scott Allen,James Avery, RussBasiura,Mike Batongbacal,Marco Bellinaso,Matt Butler,Andreas Eide,Daniel Cazzulino, MichaelClark,Richard Conway,Robert Eisenberg,Brady Gaster,James Greenwood,Kevin Hoffman, ErikJohansson,Angelo Kastroulis,Dan Kent,Sitaraman Lakshminarayanan,Don Lee,Christopher Miller, Matt Milner,Jan Narkiewicz,Matt Odhner,Ryan O’Keefe,Andrew Reid,Matthew Reynolds,Enrico Sabbadin, Bill Sempf,Doug Seven,Srinivasa Sivkumar,Thiru Thangarathinam,Doug Thews 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: 978-1-59059-776-7 ISBN-10: 1-59059-776-1 Library of Congress Cataloging-in-Publication data is available upon request. 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 Production Director and Project Manager: Grace Wong Copy Edit Manager: Nicole LeClerc Copy Editor: Kim Wimpsett Assistant Production Director: Kari Brooks-Copony Production Editor: Katie Stence Compositor: Dina Quan Artist: Kinetic Publishing Services, LLC Proofreader: Lori Bring Indexer: Broccoli Information Management 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 [email protected], 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 [email protected], 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 indi- rectly by the information contained in this work. The source code for this book is available to readers at http://www.apress.comin the Source Code/ Download section. You will need to answer questions pertaining to this book in order to successfully download the code. 7761FM.qxd 9/5/06 8:50 AM Page iii I would like to dedicate this book to a few people without whom it never would have been possible. To Yaacov and Philippe Cohen at Mainsoft, who are remarkable men creating an excellent working environment with God at its center.I appreciate every minute, every conversation,and every e-mail I get from you guys. Thanks! To my wife,Rebecca,and children,Claudia and Christopher, for their eternal patience and support. Thank you so much! To the God of Abraham,Isaac,Jacob,and Jesus through whom all things are possible. —Laurence Moroney 7761FM.qxd 9/5/06 8:50 AM Page iv Contents at a Glance About the Author. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxviii About the Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxix About the Technical Reviewer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxx Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxi PART 1 ■ ■ ■ Core Concepts ■ CHAPTER 1 Introducing ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 ■ CHAPTER 2 Visual Studio 2005 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 ■ CHAPTER 3 Web Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 ■ CHAPTER 4 Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 ■ CHAPTER 5 ASP.NET Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 ■ CHAPTER 6 State Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 PART 2 ■ ■ ■ Data Access ■ CHAPTER 7 ADO.NET Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 ■ CHAPTER 8 Data Components and the DataSet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 ■ CHAPTER 9 Data Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 ■ CHAPTER 10 Rich Data Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335 ■ CHAPTER 11 Caching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391 ■ CHAPTER 12 XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425 ■ CHAPTER 13 Files and Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469 PART 3 ■ ■ ■ Building ASP.NET Websites ■ CHAPTER 14 User Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501 ■ CHAPTER 15 Themes and Master Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523 ■ CHAPTER 16 Website Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553 ■ CHAPTER 17 Resources and Localization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599 ■ CHAPTER 18 Website Deployment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619 iv 7761FM.qxd 9/5/06 8:50 AM Page v PART 4 ■ ■ ■ Security ■ CHAPTER 19 The ASP.NET Security Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669 ■ CHAPTER 20 Forms Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 691 ■ CHAPTER 21 Membership . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 709 ■ CHAPTER 22 Windows Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 751 ■ CHAPTER 23 Authorization and Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 777 ■ CHAPTER 24 Profiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 803 ■ CHAPTER 25 Cryptography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 839 ■ CHAPTER 26 Custom Membership Providers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 867 PART 5 ■ ■ ■ Advanced User Interface ■ CHAPTER 27 Custom Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 897 ■ CHAPTER 28 Design-Time Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 939 ■ CHAPTER 29 Dynamic Graphics and GDI+ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 973 ■ CHAPTER 30 Portals with WebPart Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1005 PART 6 ■ ■ ■ Web Services ■ CHAPTER 31 Creating Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1049 ■ CHAPTER 32 Web Service Standards and Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . 1091 ■ CHAPTER 33 Advanced Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1135 PART 7 ■ ■ ■ Client-Side Programming ■ CHAPTER 34 JavaScript and Ajax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1173 ■ CHAPTER 35 Atlas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1221 ■ INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1269 v 7761FM.qxd 9/5/06 8:50 AM Page vi Contents About the Author. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxviii About the Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxix About the Technical Reviewer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxx Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxi PART 1 ■ ■ ■ Core Concepts ■ CHAPTER 1 Introducing ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 The Evolution of Web Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 The Development World Before ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 What’s Wrong with Classic ASP? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 ASP.NET 1.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Seven Important Facts About ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Fact 1:ASP.NET Is Integrated with the .NET Framework . . . . . . . . . . . . . . . 7 Fact 2:ASP.NET Is Compiled,Not Interpreted . . . . . . . . . . . . . . . . . . . . . . . . 7 Fact 3:ASP.NET Is Multilanguage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Fact 4:ASP.NET Runs Inside the Common Language Runtime . . . . . . . . . 11 Fact 5:ASP.NET Is Object-Oriented . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Fact 6:ASP.NET Is Multidevice and Multibrowser . . . . . . . . . . . . . . . . . . . . 14 Fact 7:ASP.NET Is Easy to Deploy and Configure . . . . . . . . . . . . . . . . . . . . 14 ASP.NET 2.0:The Story Continues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Visual Basic 2005 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Visual Studio 2005 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 ASP.NET 2.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 ■ CHAPTER 2 Visual Studio 2005 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 The .NET Development Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 The Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 The Visual Studio 2005 IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Websites in Visual Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Projectless Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Migrating a Visual Studio .NET Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 Designing a Web Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 vi 7761FM.qxd 9/5/06 8:50 AM Page vii ■ CONTENTS vii The Visual Studio IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Solution Explorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Document Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Error List and Task List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Server Explorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 The Code Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Adding Assembly References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 IntelliSense and Outlining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 The Coding Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 How Code-Behind Files Are Connected to Pages . . . . . . . . . . . . . . . . . . . . 50 How Control Tags Are Connected to Page Variables . . . . . . . . . . . . . . . . . . 50 How Events Are Connected to Event Handlers . . . . . . . . . . . . . . . . . . . . . . . 51 Visual Studio Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Single-Step Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Advanced Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Variable Watches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Visual Studio Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 ASP.NET Development Helper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 ■ CHAPTER 3 Web Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Page Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 HTML Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 Dynamic Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 The ASP.NET Event Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Automatic Postbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 View State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 XHTML Compliance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 Web Forms Processing Stages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Page Framework Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 User Code Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Event Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Automatic Data Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Cleanup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 A Page Flow Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 The Page As a Control Container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Showing the Control Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 The Page Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Dynamic Control Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 7761FM.qxd 9/5/06 8:50 AM Page viii viii ■ CONTENTS The Page Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Session,Application,and Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Trace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Accessing the HTTP Context in Another Class . . . . . . . . . . . . . . . . . . . . . . 101 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 ■ CHAPTER 4 Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Types of Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 The Server Control Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 HTML Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 The HtmlControl Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 The HtmlContainerControl Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 The HtmlInputControl Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 The HTML Server Control Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 Setting Style Attributes and Other Properties . . . . . . . . . . . . . . . . . . . . . . 110 Programmatically Creating Server Controls . . . . . . . . . . . . . . . . . . . . . . . . 111 Handling Server-Side Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Web Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 The WebControl Base Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 Basic Web Control Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 Enumerated Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 Focus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 The Default Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 Scrollable Panels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 Handling Web Control Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 The List Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 The Selectable List Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 The BulletedList Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 Input Validation Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 The Validation Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 The Validation Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 The BaseValidator Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 The RequiredFieldValidator Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 The RangeValidator Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 7761FM.qxd 9/5/06 8:50 AM Page ix ■ CONTENTS ix The CompareValidator Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 The RegularExpressionValidator Control . . . . . . . . . . . . . . . . . . . . . . . . . . 137 The CustomValidator Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 The ValidationSummary Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 Using the Validators Programmatically . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 Validation Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 The ASP.NET Rich Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 The AdRotator Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 The Calendar Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 ■ CHAPTER 5 ASP.NET Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 Anatomy of an ASP.NET Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 The Application Domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 Application Lifetime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 Application Updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Application Directory Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 The Global.asax Application File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 Application Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 Demonstrating Application Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 ASP.NET Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 The Machine.config File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 The Web.config File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 Configuration Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Reading and Writing Configuration Sections Programmatically . . . . . . . . 169 The Website Administration Tool (WAT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 Extending the Configuration File Structure . . . . . . . . . . . . . . . . . . . . . . . . 173 Encrypting Configuration Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 .NET Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 Creating a Component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 Using a Component Through the App_Code Directory . . . . . . . . . . . . . . . 179 Using a Component Through the Bin Directory . . . . . . . . . . . . . . . . . . . . . 180 Extending the HTTP Pipeline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 HTTP Handlers and HTTP Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 Creating a Custom HTTP Handler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 Configuring a Custom HTTP Handler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 Registering HTTP Handlers Without Configuring IIS . . . . . . . . . . . . . . . . . 187 Creating an Advanced HTTP Handler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 Creating a Custom HTTP Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.