Tải bản đầy đủ (.pdf) (1,539 trang)

652 professional ASP NET 4 in c and VB

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (40.65 MB, 1,539 trang )

www.it-ebooks.info


Related Wrox Books
Beginning ASP.NET 4: in C# and VB

Programmer to Programmer™

ISBN: 978-0-470-50221-1
This introductory book offers helpful examples in a step-by-step format and has code examples written in both C# and
Visual Basic. With this book you will gradually build a web site example that takes you through the processes of building
basic ASP.NET web pages, adding features with pre-built server controls, designing consistent pages, displaying data, and more.

Beginning Microsoft Visual C# 2010

Get more out of
wrox.com
Interact

Join the Community

Take an active role online by participating in our
P2P forums @ p2p.wrox.com

Sign up for our free monthly newsletter at
newsletter.wrox.com

Wrox Online Library

Browse


Hundreds of our books are available online
through Books24x7.com

Ready for more Wrox? We have books and
e-books available on .NET, SQL Server, Java,
XML, Visual Basic, C#/ C++, and much more!

Wrox Blox

ISBN: 978-0-470-50226-6
Using this book, you will first cover the fundamentals such as variables, flow control, and object-oriented programming and
gradually build your skills for web and Windows programming, Windows forms, and data access. Step-by-step directions walk
you through processes and invite you to “Try it Out” at every stage. By the end, you’ll be able to write useful programming code
following the steps you’ve learned in this thorough, practical book. If you’ve always wanted to master Visual C# programming,
this book is the perfect one-stop resource.

Professional Visual Basic 2010 and .NET 4
ISBN: 978-0-470-50224-2
If you’ve already covered the basics and want to dive deep into VB and .NET topics that professional programmers use most,
this is your guide. You’ll explore all the new features of Visual Basic 2010 as well as all the essential functions that you need,
including .NET features such as LINQ to SQL, LINQ to XML, WCF, and more. Plus, you’ll examine exception handling and debugging,
Visual Studio features, and ASP.NET web programming.

Professional C# 4 and .NET 4
ISBN: 978-0-470-50225-9
After a quick refresher on C# basics, the author dream team moves on to provide you with details of language and framework
features including LINQ, LINQ to SQL, LINQ to XML, WCF, WPF, Workflow, and Generics. Coverage also spans ASP.NET programming
with C#, working in Visual Studio 2010 with C#, and more. With this book, you’ll quickly get up to date on all the newest capabilities
of C# 4.


Visual Studio 2010 and .NET 4 Six-in-One
ISBN: 978-0-470-49948-1
This comprehensive resource offers all you need to know to become productive with .NET 4. Experienced author and .NET guru
Mitchel Sellers reviews all the important features of .NET 4, including .NET charting and ASP.NET charting, ASP.NET dynamic
data and jQuery, and F#. The coverage is divided into six distinctive parts for easy navigation and offers a practical approach
and complete examples.

Professional Visual Studio 2010

Download short informational pieces and code
to keep you up to date and out of trouble!

ISBN: 978-0-470-54865-3
Written by an author team of veteran programmers and developers, this book gets you quickly up to speed on what you can
expect from Visual Studio 2010. Packed with helpful examples, this comprehensive guide examines the features of Visual Studio
2010 and walks you through every facet of the Integrated Development Environment (IDE), from common tasks and functions
to its powerful tools.

WPF Programmer’s Reference: Windows Presentation Foundation with C# 2010 and .NET 4
ISBN: 978-0-470-47722-9
Written by a leading expert on Microsoft graphics programming, this richly illustrated book serves as an introduction
to WPF development and explains fundamental WPF concepts. It is packed with helpful examples and progresses through
a range of topics that gradually increase in their complexity.

Contact Us.

Visual Basic 2010 Programmer’s Reference

We always like to get feedback from our readers. Have a book idea?
Need community support? Let us know by e-mailing

www.it-ebooks.info

ISBN: 978-0-470-49983-2
Visual Basic 2010 Programmer’s Reference is a language tutorial and a reference guide to the 2010 release of Visual Basic.
The tutorial provides basic material suitable for beginners but also includes in-depth content for more advanced developers.


Professional ASP.NET 4
Introduction����������������������������������������������������������������������������������������������������������������������������������������� xxxix
Chapter 1

Application and Page Frameworks�������������������������������������������������������������������������������������1

Chapter 2

ASP.NET Server Controls and Client-Side Scripts������������������������������������������������������� 49

Chapter 3

ASP.NET Web Server Controls ��������������������������������������������������������������������������������������� 85

Chapter 4

Validation Server Controls���������������������������������������������������������������������������������������������� 157

Chapter 5

Working with Master Pages��������������������������������������������������������������������������������������������187

Chapter 6


Themes and Skins������������������������������������������������������������������������������������������������������������217

Chapter 7

Data Binding��������������������������������������������������������������������������������������������������������������������� 237

Chapter 8

Data Management with ADO.NET �������������������������������������������������������������������������������309

Chapter 9

Querying with LINQ���������������������������������������������������������������������������������������������������������� 371

Chapter 10 Working with XML and LINQ to XML ���������������������������������������������������������������������������405
Chapter 11

Introduction to the Provider Model������������������������������������������������������������������������������� 457

Chapter 12

Extending the Provider Model����������������������������������������������������������������������������������������491

Chapter 13

Site Navigation������������������������������������������������������������������������������������������������������������������519

Chapter 14


Personalization�����������������������������������������������������������������������������������������������������������������569

Chapter 15

Membership and Role Management ��������������������������������������������������������������������������� 597

Chapter 16

Portal Frameworks and Web Parts�������������������������������������������������������������������������������643

Chapter 17

HTML and CSS Design with ASP.NET �������������������������������������������������������������������������683

Chapter 18

ASP.NET AJAX����������������������������������������������������������������������������������������������������������������� 709

Chapter 19

ASP.NET AJAX Control Toolkit ������������������������������������������������������������������������������������� 749

Chapter 20 Security�����������������������������������������������������������������������������������������������������������������������������805
Chapter 21

State Management�����������������������������������������������������������������������������������������������������������835

Chapter 22 Caching�����������������������������������������������������������������������������������������������������������������������������865
Chapter 23 Debugging and Error Handling�������������������������������������������������������������������������������������895
Chapter 24 File I/O and Streams ������������������������������������������������������������������������������������������������������� 927

Chapter 25 User and Server Controls����������������������������������������������������������������������������������������������� 979
Chapter 26 Modules and Handlers������������������������������������������������������������������������������������������������� 1045

www.it-ebooks.info


Chapter 27 ASP.NET MVC����������������������������������������������������������������������������������������������������������������� 1059
Chapter 28 Using Business Objects������������������������������������������������������������������������������������������������ 1081
Chapter 29 ADO.NET Entity Framework������������������������������������������������������������������������������������������ 1105
Chapter 30 ASP.NET Dynamic Data�������������������������������������������������������������������������������������������������� 1129
Chapter 31

Working with Services���������������������������������������������������������������������������������������������������� 1153

Chapter 32 Building Global Applications�����������������������������������������������������������������������������������������1217
Chapter 33 Configuration ����������������������������������������������������������������������������������������������������������������� 1239
Chapter 34 Instrumentation ������������������������������������������������������������������������������������������������������������� 1285
Chapter 35 Administration and Management�������������������������������������������������������������������������������� 1315
Chapter 36 Packaging and Deploying ASP.NET Applications ����������������������������������������������������1337
Appendix A Migrating Older ASP.NET Projects����������������������������������������������������������������������������� 1369
Appendix B ASP.NET Ultimate Tools ������������������������������������������������������������������������������������������������ 1381
Appendix C Silverlight 3 and ASP.NET��������������������������������������������������������������������������������������������� 1399
Appendix D Dynamic Types and Languages ���������������������������������������������������������������������������������� 1419
Appendix E

ASP.NET Online Resources������������������������������������������������������������������������������������������1427

Index������������������������������������������������������������������������������������������������������������������������������������������������������������1429

www.it-ebooks.info



Professional

ASP.NET 4

www.it-ebooks.info


www.it-ebooks.info


Professional

ASP.NET 4
In C# and VB

Bill Evjen
Scott Hanselman
Devin Rader

www.it-ebooks.info


Professional ASP.NET 4: In C# and VB
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com

Copyright © 2010 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-0-470-50220-4
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
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
Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011,
fax (201) 748-6008, or online at />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 Web site 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 Web site may provide or recommendations it may make. Further,
readers should be aware that Internet Web sites 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 (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available
in electronic books.
Library of Congress Control Number: 2009943645
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, 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.

www.it-ebooks.info


To Tuija, always.
—Bill Evjen
To Momo and the boys. Toot!
—Scott Hanselman

www.it-ebooks.info


www.it-ebooks.info


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, Bill is an acclaimed author and speaker on ASP.NET and Services. He has
authored or coauthored more than 20 books including Professional C# 2010, 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). 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 Global Head of Platform Architecture for Thomson Reuters, Lipper, the international news
and financial services company (www.thomsonreuters.com). 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 on Twitter
at @billevjen.
Scott Hanselman  works for Microsoft as a Principal Program Manager Lead in the
Server and Tools Online Group, aiming to spread the good word about developing software,
most often on the Microsoft stack. Before this, Scott was the Chief Architect at Corillian,
an eFinance enabler, for 6+ years, and before Corillian, he was a Principal Consultant at
Microsoft Gold Partner for 7 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 www.hanselman.com, podcasts at www.hanselminutes.com, and
runs a team that contributes to www.asp.net, www.windowsclient.net, and www.silverlight.net.
Follow Scott on Twitter @shanselman.
Devin Rader  works at Infragistics where he focuses on delivering great experiences to
developers using their controls. He’s done work on all of the .NET platforms, but most
recently has been focused on Web technologies ASP.NET and Silverlight. As a co-founder
of the St. Louis .NET User group and a former INETA board member, and a member of
the Central New Jersey .NET user group, he’s an active supporter of the .NET developer
community. He’s also co-author or technical editor of numerous books on .NET, including
Wrox’s Silverlight 3 Programmer’s Reference. Follow Devin on Twitter @devinrader.

www.it-ebooks.info


ABOUT THE TECHNICAL EDITORS

Carlos Figueroa  has been developing and designing Web solutions for the last 8 years, participating


in international projects for the pharmaceutical industry, banking, commercial air transportation, and the
government. During these years, Carlos has been deeply involved as an early adopter of Microsoft Web
development technologies, such as ASP.NET and Silverlight.

He has been awarded Microsoft Most Valuable Professional for the last 5 years and holds the MCAD
certification. Carlos is a Senior Software Developer at Oshyn, Inc. (www.oshyn.com), a company
specialized on delivering innovative business solutions for the web, mobile devices and emerging
technology platforms. At Oshyn, Carlos is dedicated to help some of the most recognizable brands in the
world to achieve technology success. You can reach Carlos at or follow
him on twitter @carlosfigueroa.
Andrew Moore  is a graduate of Purdue University–Calumet in Hammond, Indiana, and has been

developing software since 1998 for radar systems, air traffic management, discrete-event simulation, and
business communications applications using C, C++, C#, and Java on the Windows, UNIX, and Linux
platforms. Andrew is also a contributor to the Wrox Blox article series.
He is currently working as a Senior Software Engineer at Interactive Intelligence, Inc., in Indianapolis,
Indiana, developing server-side applications for a multimedia unified business communications platform.
Andrew lives in Indiana with his wife Barbara and children Sophia and Andrew.

www.it-ebooks.info


CREDITS
Acquisitions Editor

Vice President and Executive Group
Publisher

Paul Reese


Richard Swadley
Senior Project Editor

Kevin Kent

Vice President and Executive Publisher

Barry Pruett
Technical Editors

Carlos Figueroa
Andrew Moore

Associate Publisher

Production Editor

Project Coordinator, Cover

Daniel Scribner

Lynsey Stanford

Copy Editor

Proofreaders

Paula Lowell

Word One


Editorial Director

Indexer

Robyn B. Siesky

J & J Indexing

Editorial Manager

Cover Designer

Mary Beth Wakefield

Michael E. Trent

Associate Director of Marketing

Cover Image

David Mayhew

© Jon Feingersh Photography Inc / Blend
Images / Jupiter Images

Jim Minatel

Production Manager


Tim Tate

www.it-ebooks.info


www.it-ebooks.info


ACKNOWLEDGMENTS

Thanks to Kevin Kent, Paul Reese, and Jim Minatel  for the opportunity to work on such a great

book. In addition to my co-authors, I would like to thank my family for putting up with all the writing.
Thank you Tuija, Sofia, Henri, and Kalle!

—Bill Evjen

www.it-ebooks.info


www.it-ebooks.info


Contents

Introduction

xxxix

Chapter 1: Application and Page Frameworks


Application Location Options
Built-in Web Server
IIS
FTP
Web Site Requiring FrontPage Extensions

The ASP.NET Page Structure Options
Inline Coding
Code-Behind Model

1

1
2
3
3
4

4
6
7

ASP.NET 4 Page Directives

9

@Page
@Master
@Control

@Import
@Implements
@Register
@Assembly
@PreviousPageType
@MasterType
@OutputCache
@Reference

10
13
14
15
17
17
18
18
18
18
19

ASP.NET Page Events
Dealing with Postbacks
Cross-Page Posting
ASP.NET Application Folders

19
20
21
26


App_Code Folder
App_Data Folder
App_Themes Folder
App_GlobalResources Folder
App_LocalResources Folder
App_WebReferences Folder
App_Browsers Folder

27
30
31
31
31
31
31

Compilation
Build Providers

32
35

www.it-ebooks.info


CONTENTS

Using the Built-in Build Providers
Using Your Own Build Providers


Global.asax
Working with Classes Through Visual Studio 2010
Summary

36
36

41
44
47

Chapter 2: ASP.NET Server Controls and Client-Side Scripts 49

ASP.NET Server Controls

49

Types of Server Controls
Building with Server Controls
Working with Server Control Events

50
51
53

Applying Styles to Server Controls

54


Examining the Controls’ Common Properties
Changing Styles Using Cascading Style Sheets
CSS Changes in ASP.NET 4

HTML Server Controls

54
56
58

59

Looking at the HtmlControl Base Class
Looking at the HtmlContainerControl Class
Looking at All the HTML Classes
Using the HtmlGenericControl Class

Identifying ASP.NET Server Controls
Manipulating Pages and Server Controls with JavaScript
Using Page.ClientScript.RegisterClientScriptBlock
Using Page.ClientScript.RegisterStartupScript
Using Page.ClientScript.RegisterClientScriptInclude

Client-Side Callback

60
61
61
62


63
65
66
68
69

69

Comparing a Typical Postback to a Callback
Using the Callback Feature — A Simple Approach
Using the Callback Feature with a Single Parameter
Using the Callback Feature — A More Complex Example

Summary

70
72
75
78

83

Chapter 3: ASP.NET Web Server Controls

An Overview of Web Server Controls
The Label Server Control
The Literal Server Control
The TextBox Server Control
Using the Focus() Method
Using AutoPostBack

Using AutoCompleteType

xvi

www.it-ebooks.info

85

85
86
88
88
89
89
90


CONTENTS

The Button Server Control

91

The CausesValidation Property
The CommandName Property
Buttons That Work with Client-Side JavaScript

91
92
93


The LinkButton Server Control
The ImageButton Server Control
The HyperLink Server Control
The DropDownList Server Control
Visually Removing Items from a Collection
The ListBox Server Control

94
95
96
96
98
100

Allowing Users to Select Multiple Items
An Example of Using the ListBox Control
Adding Items to a Collection

100
100
102

The CheckBox Server Control
How to Determine Whether Check Boxes Are Checked
Assigning a Value to a Check Box
Aligning Text Around the Check Box

The CheckBoxList Server Control
The RadioButton Server Control

The RadioButtonList Server Control
Image Server Control
Table Server Control
The Calendar Server Control
Making a Date Selection from the Calendar Control
Choosing a Date Format to Output from the Calendar
Making Day, Week, or Month Selections
Working with Date Ranges
Modifying the Style and Behavior of Your Calendar

AdRotator Server Control
The Xml Server Control
Panel Server Control
The PlaceHolder Server Control
BulletedList Server Control
HiddenField Server Control
FileUpload Server Control
Uploading Files Using the FileUpload Control
Giving ASP.NET Proper Permissions to Upload Files
Understanding File Size Limitations
Uploading Multiple Files from the Same Page
Placing the Uploaded File into a Stream Object
Moving File Contents from a Stream Object to a Byte Array

102
103
104
104

104

106
108
109
110
112
112
113
114
115
116

119
121
122
124
124
129
130
130
132
133
134
137
137

xvii

www.it-ebooks.info



CONTENTS

MultiView and View Server Controls
Wizard Server Control
Customizing the Side Navigation
Examining the AllowReturn Attribute
Working with the StepType Attribute
Adding a Header to the Wizard Control
Working with the Wizard’s Navigation System
Utilizing Wizard Control Events
Using the Wizard Control to Show Form Elements

ImageMap Server Control
Chart Server Control
Summary

138
141
142
143
143
143
144
145
146

150
152
155


Chapter 4: Validation Server Controls

157

Understanding Validation
Client-Side versus Server-Side Validation
ASP.NET Validation Server Controls

157
158
159

Validation Causes
The RequiredFieldValidator Server Control
The CompareValidator Server Control
The RangeValidator Server Control
The RegularExpressionValidator Server Control
The CustomValidator Server Control
The ValidationSummary Server Control

160
160
164
167
171
172
176

Turning Off Client-Side Validation
Using Images and Sounds for Error Notifications

Working with Validation Groups
Summary

179
180
181
185

Chapter 5: Working with Master Pages

Why Do You Need Master Pages?
The Basics of Master Pages
Coding a Master Page
Coding a Content Page
Mixing Page Types and Languages
Specifying Which Master Page to Use
Working with the Page Title
Working with Controls and Properties from the Master Page

Specifying Default Content in the Master Page
Programmatically Assigning the Master Page

xviii

www.it-ebooks.info

187

187
189

190
192
196
197
198
199

205
207


CONTENTS

Nesting Master Pages
Container-Specific Master Pages
Event Ordering
Caching with Master Pages
ASP.NET AJAX and Master Pages
Summary
Chapter 6: Themes and Skins

Using ASP.NET Themes

207
211
212
213
214
216
217


217

Applying a Theme to a Single ASP.NET Page
Applying a Theme to an Entire Application
Removing Themes from Server Controls
Removing Themes from Web Pages
Understanding Themes When Using Master Pages
Understanding the StyleSheetTheme Attribute

Creating Your Own Themes

217
219
219
220
221
221

222

Creating the Proper Folder Structure
Creating a Skin
Including CSS Files in Your Themes
Having Your Themes Include Images

Defining Multiple Skin Options
Programmatically Working with Themes
Assigning the Page’s Theme Programmatically
Assigning a Control’s SkinID Programmatically


Themes, Skins, and Custom Controls
Summary
Chapter 7: Data Binding

222
222
224
227

229
231
231
231

232
235
237

Data Source Controls

237

SqlDataSource Control
AccessDataSource Control
LinqDataSource Control
EntityDataSource Control
XmlDataSource Control
ObjectDataSource Control
SiteMapDataSource Control


239
247
247
253
255
256
259

Data Source Control Caching
Storing Connection Information
Using Bound List Controls with Data Source Controls
GridView

259
260
262
262

xix

www.it-ebooks.info


CONTENTS

Editing GridView Row Data
Deleting GridView Data
Other GridView Formatting Features
DetailsView

Inserting, Updating, and Deleting Data Using DetailsView
ListView
FormView

Other Databound Controls
TreeView
AdRotator
Menu

275
281
283
283
287
289
296

300
300
301
301

Inline Data-Binding Syntax
Data-Binding Syntax
XML Data Binding

302
302
303


Expressions and Expression Builders
Summary
Chapter 8: Data Management with ADO.NET

Basic ADO.NET Features
Common ADO.NET Tasks
Basic ADO.NET Namespaces and Classes
Using the Connection Object
Using the Command Object
Using the DataReader Object
Using DataAdapter
Using Parameters
Understanding DataSet and DataTable
Using Oracle as Your Database with ASP.NET

The DataList Server Control
Looking at the Available Templates
Working with ItemTemplate
Working with Other Layout Templates
Working with Multiple Columns

The ListView Server Control
Connecting the ListView to a Database
Creating the Layout Template
Creating the ItemTemplate
Creating the EditItemTemplate
Creating the EmptyItemTemplate
Creating the InsertItemTemplate
Viewing the Results


xx

www.it-ebooks.info

303
308
309

310
310
314
315
317
318
320
322
325
329

330
331
331
334
336

336
337
338
340
341

341
341
342


CONTENTS

Using Visual Studio for ADO.NET Tasks
Creating a Connection to the Data Source
Working with a Dataset Designer
Using the CustomerOrders DataSet

Asynchronous Command Execution
Asynchronous Methods of the SqlCommand Class
IAsyncResult Interface
AsyncCallback
WaitHandle Class
Approaches of Asynchronous Processing in ADO.NET
Canceling Asynchronous Processing
Asynchronous Connections

Summary

344
344
345
348

352
352

353
354
354
355
370
370

370

Chapter 9: Querying with LINQ

LINQ to Objects

371

371

Understanding Traditional Query Methods
Replacing Traditional Queries with LINQ
Data Grouping
Using Other LINQ Operators
Making LINQ Joins
Paging Using LINQ

LINQ to XML

371
378
384
385

385
386

387

Joining XML Data

390

LINQ to SQL

391

Making Insert, Update, and Delete Queries through LINQ
Extending LINQ

Summary

399
403

403

Chapter 10: Working with XML and LINQ to XML

The Basics of XML

405

406


The XML InfoSet
XSD–XML Schema Definition
Editing XML and XML Schema in Visual Studio 2010

XmlReader and XmlWriter

408
409
410

413

Using XDocument Rather Than XmlReader
Using Schema with XmlTextReader
Validating Against a Schema Using an XDocument
Including NameTable Optimization
Retrieving .NET CLR Types from XML

415
416
417
419
420

xxi

www.it-ebooks.info



CONTENTS

ReadSubtree and XmlSerialization
Creating CLR Objects from XML with LINQ to XML
Creating XML with XmlWriter
Creating XML with LINQ for XML
Improvements for XmlReader and XmlWriter

XmlDocument and XPathDocument
Problems with the DOM
XPath, the XPathDocument, and XmlDocument

DataSets

422
423
424
426
429

429
429
430

434

Persisting DataSets to XML
XmlDataDocument

The XmlDataSource Control

XSLT
XslCompiledTransform
XSLT Debugging

434
435

437
441
442
445

Databases and XML

446

FOR XML AUTO
SQL Server and the XML Data Type

Summary

446
451

456

Chapter 11: Introduction to the Provider Model

Understanding the Provider
The Provider Model in ASP.NET 4

Setting Up Your Provider to Work with Microsoft SQL Server
7.0, 2000, 2005, or 2008
Membership Providers
Role Providers
The Personalization Provider
The SiteMap Provider
SessionState Providers
Web Event Providers
Configuration Providers
The Web Parts Provider

Configuring Providers
Summary

457

458
459
461
466
469
473
474
476
478
485
487

489
489


Chapter 12: Extending the Provider Model

Providers Are One Tier in a Larger Architecture
Modifying Through Attribute-Based Programming
Simpler Password Structures Through the SqlMembershipProvider
Stronger Password Structures Through the SqlMembershipProvider
xxii

www.it-ebooks.info

491

491
492
492
495


CONTENTS

Examining ProviderBase
Building Your Own Providers
Creating the CustomProviders Application
Constructing the Class Skeleton Required
Creating the XML User Data Store
Defining the Provider Instance in the web.config File
Not Implementing Methods and Properties of the
MembershipProvider Class
Implementing Methods and Properties of

the MembershipProvider Class
Using the XmlMembershipProvider for User Login

Extending Pre-Existing Providers
Limiting Role Capabilities with a New LimitedSqlRoleProvider Provider
Using the New LimitedSqlRoleProvider Provider

Summary

496
497
498
499
502
502
503
504
510

511
511
515

518

Chapter 13: Site Navigation

519

XML-Based Sitemaps

SiteMapPath Server Control

520
521

The PathSeparator Property
The PathDirection Property
The ParentLevelsDisplayed Property
The ShowToolTips Property
The SiteMapPath Control’s Child Elements

TreeView Server Control

523
525
525
526
526

527

Identifying the TreeView Control’s Built-In Styles
Examining the Parts of the TreeView Control
Binding the TreeView Control to an XML File
Selecting Multiple Options in a TreeView
Specifying Custom Icons in the TreeView Control
Specifying Lines Used to Connect Nodes
Working with the TreeView Control Programmatically

Menu Server Control


530
531
532
534
537
538
540

545

Applying Different Styles to the Menu Control
Using Menu Events
Binding the Menu Control to an XML File

546
550
551

SiteMap Data Provider

552

ShowStartingNode
StartFromCurrentNode
StartingNodeOffset
StartingNodeUrl

552
553

554
555

SiteMap API

555
xxiii

www.it-ebooks.info


×