Evjen Professional ASP.NET 3.5 In C# and VB Bill Evjen Scott Hanselman Devin Rader Wiley Publishing, Inc ffirs.tex V2 - 01/28/2008 4:55pm Page iii Evjen ffirs.tex V2 - 01/28/2008 4:55pm Page ii Evjen ffirs.tex V2 - 01/28/2008 4:55pm Professional ASP.NET 3.5 In C# and VB Chapter 1: Application and Page Frameworks Chapter 2: ASP.NET Server Controls and Client-Side Scripts 63 Chapter 3: ASP.NET Web Server Controls 107 Chapter 4: Validation Server Controls 193 Chapter 5: Working with Master Pages 229 Chapter 6: Themes and Skins 263 Chapter 7: Data Binding in ASP.NET 3.5 287 Chapter 8: Data Management with ADO.NET 377 Chapter 9: Querying with LINQ 455 Chapter 10: Working with XML and LINQ to XML 497 Chapter 11: IIS7 557 Chapter 12: Introduction to the Provider Model 587 Chapter 13: Extending the Provider Model 627 Chapter 14: Site Navigation 661 Chapter 15: Personalization 723 Chapter 16: Membership and Role Management 757 Chapter 17: Portal Frameworks and Web Parts 811 Chapter 18: HTML and CSS Design with ASP.NET 861 Chapter 19: ASP.NET AJAX 895 Chapter 20: ASP.NET AJAX Control Toolkit 929 Chapter 21: Security 995 Chapter 22: State Management 1033 Chapter 23: Caching 1071 Chapter 24: Debugging and Error Handling 1103 Chapter 25: File I/O and Streams 1139 Chapter 26: User and Server Controls 1193 Chapter 27: Modules and Handlers 1275 Chapter 28: Using Business Objects 1297 Chapter 29: Building and Consuming Services 1325 Chapter 30: Localization 1381 Chapter 31: Configuration 1409 Chapter 32: Instrumentation 1461 Chapter 33: Administration and Management 1499 Chapter 34: Packaging and Deploying ASP.NET Applications 1529 Appendix A: Migrating Older ASP.NET Projects 1567 Appendix B: ASP.NET Ultimate Tools 1583 Appendix C: Silverlight 1607 Appendix D: ASP.NET Online Resources 1627 Index 1629 Page i Evjen ffirs.tex V2 - 01/28/2008 4:55pm Page ii Evjen Professional ASP.NET 3.5 In C# and VB Bill Evjen Scott Hanselman Devin Rader Wiley Publishing, Inc ffirs.tex V2 - 01/28/2008 4:55pm Page iii Evjen ffirs.tex V2 - 01/28/2008 Professional ASP.NET 3.5 In C# and VB Published by Wiley Publishing, Inc 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2008 by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-0-470-18757-9 Manufactured in the United States of America 10 Library of Congress Cataloging-in-Publication Data is available from the publisher No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600 Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose No warranty may be created or extended by sales or promotional materials The advice and strategies contained herein may not be suitable for every situation This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services If professional assistance is required, the services of a competent professional person should be sought Neither the publisher nor the author shall be liable for damages arising herefrom The fact that an organization or Website is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Website may provide or recommendations it may make Further, readers should be aware that Internet Websites listed in this work may have changed or disappeared between when this work was written and when it is read For general information on our other products and services please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002 Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc and/or its affiliates, in the United States and other countries, and may not be used without written permission All other trademarks are the property of their respective owners Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book Wiley also publishes its books in a variety of electronic formats Some content that appears in print may not be available in electronic books 4:55pm Page iv Evjen fauth.tex V1 - 02/20/2008 1:50am About the Authors Bill Evjen is an active proponent of NET technologies and community-based learning initiatives for NET He has been actively involved with NET since the first bits were released in 2000 In the same year, Bill founded the St Louis NET User Group (www.stlnet.org), one of the world’s first such groups Bill is also the founder and former executive director of the International NET Association (www.ineta.org), which represents more than 500,000 members worldwide Based in St Louis, Missouri, USA, Bill is an acclaimed author and speaker on ASP.NET and XML Web Services He has authored or co-authored more than fifteen books including Professional C# 2008, Professional VB 2008, ASP.NET Professional Secrets, XML Web Services for ASP.NET, and Web Services Enhancements: Understanding the WSE for Enterprise Applications (all published by Wiley Publishing, Inc.) In addition to writing, Bill is a speaker at numerous conferences, including DevConnections, VSLive, and TechEd Along with these items, Bill works closely with Microsoft as a Microsoft Regional Director and an MVP Bill is the Technical Architect for Lipper (www.lipperweb.com), a wholly-owned subsidiary of Reuters, the international news and financial services company He graduated from Western Washington University in Bellingham, Washington, with a Russian language degree When he isn’t tinkering on the computer, he can usually be found at his summer house in Toivakka, Finland You can reach Bill at evjen@yahoo.com Scott Hanselman works for Microsoft as a Senior Program Manager in the Developer Division, aiming to spread the good word about developing software, most often on the Microsoft stack Before this he worked in eFinance for 6+ years and before that he was a Principal Consultant at a Microsoft Partner for nearly years He was also involved in a few things like the MVP and RD programs and will speak about computers (and other passions) whenever someone will listen to him He blogs at http://www.hanselman.com and podcasts at http://www.hanselminutes.com and contributes to http://www.asp.net, http://www.windowsclient.net, and http://www.silverlight.net Devin Rader is a Product Manager on the Infragistics Web Client team, responsible for leading the creation of Infragistics ASP.NET and Silverlight products Devin is also an active proponent and member of the NET developer community, being a co-founder of the St Louis NET User Group, an active member of the New Jersey NET User Group, a former board member of the International NET Association (INETA), and a regular speaker at user groups He is also a contributing author on the Wrox title Silverlight 1.0 and a technical editor for several other Wrox publications and has written columns for ASP.NET Pro magazine, as well as NET technology articles for MSDN Online You can find more of Devin’s musings at www.geekswithblogs.com/devin Page v Evjen fauth.tex V1 - 01/28/2008 4:58pm Page vi Evjen fcredit.tex V1 - 01/28/2008 4:59pm Credits Acquisitions Director Editorial Manager Jim Minatel Mary Beth Wakefield Development Editors Production Manager Adaobi Obi Tulton Sydney Jones Tim Tate Vice President and Executive Group Publisher Technical Editors Eric Engler Alexei Gorkov Doug Holland Darren Kindberg Mark Strawmeyr Richard Swadley Vice President and Executive Publisher Joseph B Wikert Project Coordinator, Cover Lynsey Stanford Production Editor Angela Smith Proofreader Sossity Smith Copy Editors Nancy Rapoport Sydney Jones Indexer J & J Indexing Page vii ... WCF Overview Building a WCF Service 132 8 132 9 133 0 133 3 133 6 133 6 133 8 134 1 134 2 134 4 134 5 134 6 134 9 1 35 0 1 35 1 1 35 3 1 35 5 1 35 7 136 0 136 0 136 1 136 2 Building the WCF Consumer 137 0 Adding a Service... (UserControl) Caching Post-Cache Substitution HttpCachePolicy and Client-Side Caching Caching Programmatically Data Caching Using the Cache Object Controlling the ASP. NET Cache Cache Dependencies... 50 8 50 9 51 1 5 13 51 5 51 7 51 8 51 9 52 2 52 4 52 5 52 5 52 5 53 0 53 0 53 1 xv Evjen ftoc.tex V2 - 01/28 /2008 Contents The XmlDataSource Control XSLT XslCompiledTransform XSLT Debugging Databases and XML