ebook img

Pro ASP.NET 4 in C# 2010, 4th Edition PDF

1617 Pages·2010·38.53 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 4 in C# 2010, 4th Edition

CYAN YELLOW MAGENTA BLACK PANTONE 123 C BOOKS FOR PROFESSIONALS BY PROFESSIONALS® THE EXPERT’S VOICE® IN .NET Companion eBook Available Matthew MacDonald, Author of Pro ASP.NET 4 in C# 2010 Pro Silverlight 4 in C# Pro Beginning ASP.NET 4 in C# Dear Reader, 2010 Pro WPF in C# 2010 As you know, ASP.NET is Microsoft’s premier technology for creating server- side web applications. In this book, you’ll learn about ASP.NET 4, which is the Pro Pro .NET 2.0 Windows i A latest milestone in web development. Forms and Custom Controls n ASP.NET 4 adds a host of refinements and two major new features to pre- vious versions of the technology. The first major change is the inclusion of Adam Freeman, ASP.NET MVC—an alternative way to design web pages—that offers clean- S Co-Author of C ASP.NET 4 er URLs, better testability, and tight control over HTML. The second is ASP. Introducing Visual C# 2010 NET Dynamic Data—a data scaffolding framework that allows you to build Pro .NET 4 Parallel an entire website out of flexible, reusable templates. You’ll learn about both Programming in C# of these innovations in this book. You’ll also get a solid look at Silverlight, # P Pro LINQ: Language Microsoft’s next-generation browser plug-in that allows you to draw vector Integrated Query in C# graphics, show animations, and play media files in your ASP.NET pages. 2010 . Visual C# 2010 Recipes The book also covers: 2 C# 2010 N • Core concepts of ASP.NET 4. You’ll learn the fundamentals of Visual Studio, ASP. Programming .NET Security NET, and the web forms model—and how to extend this infrastructure when in Microsoft .NET XML Web you need to. 0 Services Step by Step • Data access. You’ll get a thorough review of scalable data access programming, C# for Java Developers covering pure ADO.NET, LINQ, the Entity Framework, ASP.NET Dynamic Data, E Programming the Internet and advanced caching techniques. 1 with Java • Security. You’ll learn to secure your website with ASP.NET’s built-in authoriza- tion and authentication features, and how to protect sensitive data wherever it’s Active Java stored with encryption. 0 T • Advanced user interface. You’ll study a range of techniques for building pages with Mario Szpuszta, pizzazz, including CSS, custom controls, GDI+, JavaScript, and ASP.NET AJAX. Co-Author of • And much more… Advanced .NET Remoting Matthew MacDonald (Microsoft MVP, MCSD) 4 Companion eBook THE APRESS ROADMAP Pro Pro C# 2010 Windows Azure Introducing .NET 4.0 and the FOURTH EDITION .NET 4 Platform See last page for details Pro FOURTH EDITION on $10 eBook version Silverlight 4 in C# Accelerated Pro ASP.NET 4 C# 2010 in C# 2010, Pro Dynamic .NET 4.0 Applications M SFa Matthew MacDonald, Adam Freeman, SOURCE CODE ONLINE zrc www.apress.com peD ISBN 978-1-4302-2529-4 ueo 55999 smn and Mario Szpuszta z a a US $59.99 tanld Shelve in: .NET User level: Intermediate–Advanced 9 781430 225294 www.it-ebooks.info this print for content only—size & color not accurate 7.5 x 9.25 spine = 3.03125" 1616 page count 2529-4 MacDonald.indd 1 6/7/10 12:08 PM www.it-ebooks.info Pro ASP.NET 4 in C# 2010 Fourth Edition ■ ■ ■ Matthew MacDonald, Adam Freeman, and Mario Szpuszta www.it-ebooks.info Pro ASP.NET in C# 2010, Fourth Edition Copyright © 2010 by Matthew MacDonald, Adam Freeman, and Mario Szpuszta 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 the publisher. ISBN-13 (pbk): 978-1-4302-2529-4 ISBN-13 (electronic): 978-1-4302-2530-0 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. President and Publisher: Paul Manning Lead Editor: Ewan Buckingham Technical Reviewers: Fabio Claudio Ferracchiati and Todd Meister Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Coordinating Editor: Anne Collett Copy Editors: Ralph Moore, Katie Stence, Kim Wimpsett Compositor: Mary Sudul Indexer: Kevin Broccoli Artist: April Milne Cover Designer: Anna Ishchenko Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders- [email protected], or visit www.springeronline.com. For information on translations, please e-mail [email protected], or visit www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/info/bulksales. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at www.apress.com. You will need to answer questions pertaining to this book in order to successfully download the code. www.it-ebooks.info Contents at a Glance Contents....................................................................................................................v About the Author................................................................................................xxxii About the Technical Reviewer...........................................................................xxxiii Introduction.......................................................................................................xxxiv Part 1: Core Concepts...............................................................................................1 ■ Chapter 1: Introducing ASP.NET...........................................................................3 ■ Chapter 2: Visual Studio.....................................................................................21 ■ Chapter 3: Web Forms........................................................................................77 ■ Chapter 4: Server Controls...............................................................................129 ■ Chapter 5: ASP.NET Applications.....................................................................183 ■ Chapter 6: State Management.........................................................................235 Part 2: Data Access..............................................................................................275 ■ Chapter 7: ADO.NET Fundamentals..................................................................277 ■ Chapter 8: Data Components and the DataSet.................................................321 ■ Chapter 9: Data Binding...................................................................................353 ■ Chapter 10: Rich Data Controls........................................................................403 ■ Chapter 11: Caching and Asynchronous Pages...............................................477 ■ Chapter 12: Files and Streams.........................................................................527 ■ Chapter 13: LINQ..............................................................................................563 ■ Chapter 14: XML...............................................................................................617 iii www.it-ebooks.info Part 3: Building ASP.NET Websites.......................................................................679 ■ Chapter 15: User Controls................................................................................681 ■ Chapter 16: Themes and Master Pages...........................................................703 ■ Chapter 17: Website Navigation.......................................................................735 ■ Chapter 18: Website Deployment.....................................................................791 Part 4: Security.....................................................................................................833 ■ Chapter 19: The ASP.NET Security Model........................................................835 ■ Chapter 20: Forms Authentication...................................................................851 ■ Chapter 21: Membership..................................................................................877 ■ Chapter 22: Windows Authentication...............................................................933 ■ Chapter 23: Authorization and Roles...............................................................963 ■ Chapter 24: Profiles.........................................................................................995 ■ Chapter 25: Cryptography..............................................................................1029 ■ Chapter 26: Custom Membership Providers..................................................1061 Part 5: Advanced User Interface.........................................................................1099 ■ Chapter 27: Custom Server Controls..............................................................1101 ■ Chapter 28: Graphics, GDI+, and Charting.....................................................1135 ■ Chapter 29: JavaScript and Ajax Techniques................................................1179 ■ Chapter 30: ASP.NET AJAX.............................................................................1239 ■ Chapter 31: Portals with Web Part Pages......................................................1303 ■ Chapter 32: MVC............................................................................................1363 ■ Chapter 33: Dynamic Data.............................................................................1397 ■ Chapter 34: Silverlight...................................................................................1437 Index...................................................................................................................1491 iv www.it-ebooks.info ■ CONTENTS Contents Contents at a Glance................................................................................................iii About the Author................................................................................................xxxii About the Technical Reviewer...........................................................................xxxiii Introduction.......................................................................................................xxxiv Part 1: Core Concepts...............................................................................................1 ■ Chapter 1: Introducing ASP.NET...........................................................................3 The Seven Pillars of ASP.NET..........................................................................................3 #1: ASP.NET Is Integrated with the .NET Framework.............................................................................3 #2: ASP.NET Is Compiled, Not Interpreted..............................................................................................4 #3: ASP.NET Is Multilanguage................................................................................................................6 #4: ASP.NET Is Hosted by the Common Language Runtime...................................................................8 #5: ASP.NET Is Object-Oriented..............................................................................................................9 #6: ASP.NET Supports all Browsers......................................................................................................11 #7: ASP.NET Is Easy to Deploy and Configure......................................................................................11 The Evolution of ASP.NET..............................................................................................12 ASP.NET 1.0 and 1.1.............................................................................................................................12 ASP.NET 2.0..........................................................................................................................................12 ASP.NET 3.5..........................................................................................................................................13 ASP.NET 4.............................................................................................................................................16 Silverlight.............................................................................................................................................18 Summary.......................................................................................................................19 v www.it-ebooks.info ■ CONTENTS ■ Chapter 2: Visual Studio.....................................................................................21 Introducing Visual Studio...............................................................................................21 Websites and Web Projects..................................................................................................................22 Creating a Projectless Website.............................................................................................................23 Designing a Web Page..........................................................................................................................28 The Visual Studio IDE.....................................................................................................35 Solution Explorer..................................................................................................................................37 Document Window...............................................................................................................................38 Toolbox.................................................................................................................................................38 Error List and Task List.........................................................................................................................39 Server Explorer.....................................................................................................................................41 The Code Editor.............................................................................................................42 Adding Assembly References...............................................................................................................43 IntelliSense and Outlining.....................................................................................................................46 Visual Studio 2010 Improvements........................................................................................................50 The Code Model.............................................................................................................56 How Code-Behind Files Are Connected to Pages.................................................................................59 How Control Tags Are Connected to Page Variables............................................................................60 How Events Are Connected to Event Handlers.....................................................................................61 Web Projects..................................................................................................................63 Creating a Web Project.........................................................................................................................64 Migrating a Website from a Previous Version of Visual Studio.............................................................66 Visual Studio Debugging................................................................................................68 Single-Step Debugging.........................................................................................................................69 Variable Watches..................................................................................................................................72 Advanced Breakpoints..........................................................................................................................74 The Web Development Helper.......................................................................................74 Summary.......................................................................................................................76 ■ Chapter 3: Web Forms........................................................................................77 Page Processing............................................................................................................78 HTML Forms.........................................................................................................................................78 vi www.it-ebooks.info ■ CONTENTS Dynamic User Interface........................................................................................................................80 The ASP.NET Event Model....................................................................................................................81 Automatic Postbacks............................................................................................................................82 View State............................................................................................................................................84 XHTML Compliance...............................................................................................................................88 Client-Side Control IDs.........................................................................................................................94 Web Forms Processing Stages......................................................................................97 Page Framework Initialization..............................................................................................................98 User Code Initialization.........................................................................................................................99 Validation..............................................................................................................................................99 Event Handling....................................................................................................................................100 Automatic Data Binding......................................................................................................................100 Cleanup...............................................................................................................................................101 A Page Flow Example.........................................................................................................................101 The Page As a Control Container.................................................................................104 Showing the Control Tree...................................................................................................................104 The Page Header................................................................................................................................109 Dynamic Control Creation...................................................................................................................110 The Page Class............................................................................................................112 Session, Application, and Cache........................................................................................................112 Request..............................................................................................................................................113 Response............................................................................................................................................114 Server.................................................................................................................................................118 User....................................................................................................................................................121 Trace...................................................................................................................................................121 Accessing the HTTP Context in Another Class....................................................................................127 Summary.....................................................................................................................128 ■ Chapter 4: Server Controls...............................................................................129 Types of Server Controls..............................................................................................129 The Server Control Hierarchy.............................................................................................................130 HTML Server Controls..................................................................................................132 The HtmlControl Class........................................................................................................................133 vii www.it-ebooks.info ■ CONTENTS The HtmlContainerControl Class.........................................................................................................133 The HtmlInputControl Class................................................................................................................134 The HTML Server Control Classes......................................................................................................134 Setting Style Attributes and Other Properties.....................................................................................136 Programmatically Creating Server Controls.......................................................................................137 Handling Server-Side Events..............................................................................................................139 Web Controls...............................................................................................................142 The WebControl Base Class................................................................................................................143 Basic Web Control Classes.................................................................................................................145 Units...................................................................................................................................................147 Enumerations.....................................................................................................................................147 Colors.................................................................................................................................................148 Fonts...................................................................................................................................................148 Focus..................................................................................................................................................150 The Default Button..............................................................................................................................151 Scrollable Panels................................................................................................................................152 Handling Web Control Events.............................................................................................................153 The List Controls..........................................................................................................156 The Selectable List Controls...............................................................................................................157 The BulletedList Control.....................................................................................................................161 Input Validation Controls..............................................................................................162 The Validation Controls.......................................................................................................................163 The Validation Process.......................................................................................................................164 The BaseValidator Class.....................................................................................................................165 The RequiredFieldValidator Control....................................................................................................167 The RangeValidator Control................................................................................................................167 The CompareValidator Control............................................................................................................168 The RegularExpressionValidator Control............................................................................................168 The CustomValidator Control..............................................................................................................171 The ValidationSummary Control.........................................................................................................172 Using the Validators Programmatically..............................................................................................174 Validation Groups................................................................................................................................175 viii www.it-ebooks.info

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.