Tải bản đầy đủ (.pdf) (844 trang)

Beginning ASP.NET 4: in C# and VB potx

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 (13.27 MB, 844 trang )

Wrox Programmer to Programmer™
Join the discussion @ p2p.wrox.com

Beginning
ASP.NET 4
in C# and VB
Imar Spaanjaars
Spaanjaars
$44.99 USA
$53.99 CAN
Web Development/ASP.NET
Build rich web sites with
the latest version of ASP.NET
wrox.com
Programmer
Forums
Join our Programmer to
Programmer forums to ask
and answer programming
questions about this book,
join discussions on the
hottest topics in the industry,
and connect with fellow
programmers from around
the world.
Code Downloads
Take advantage of free code
samples from this book, as
well as code samples from
hundreds of other books, all
ready to use.


Read More
Find articles, ebooks, sample
chapters, and tables of contents
for hundreds of books, and
more reference resources on
programming topics that matter
to you.
ASP.NET is the part of the .NET Framework that enables you to
build rich, dynamic web sites. The latest version—ASP.NET 4—boasts
numerous improvements to the previous iteration, including Web
Forms enhancements and jQuery support. This step-by-step book
walks you through building rich web sites with ASP.NET 4 and is
packed with in-depth examples in both C# and VB. With hands-on
exercises that take you right into the action, you’ll learn how to build web
sites firsthand while you get a good look at what goes on behind
the scenes when you view an ASP.NET 4 page in your browser.
Beginning ASP.NET 4:
• Demonstrates how to build ASP.NET 4 web pages
• Explains adding features with pre-built server controls
• Reviews working with the development tools to create ASP.NET web sites
• Shares techniques for creating consistent-looking web sites
• Teaches you how to implement jQuery and AJAX techniques in your
web sites
• Shows you how to work with databases and the Microsoft
®
ADO.NET
Entity Framework
• Addresses securing and personalizing your site
• Investigates exception handling, debugging, and tracing pages
Imar Spaanjaars is a Microsoft ASP.NET MVP and runs his own company called

De Vier Koeden in the Netherlands, specializing in Internet and intranet applications
built with Microsoft technologies like ASP
.NET 4. He is the author or coauthor of
several books, including ASP.NET 2.0 Instant Results and Beginning ASP.NET 3.5
in C# and VB, and is one of the top contributors to the Wrox Community
Forum at p2p.wrox.com.
Wrox Beginning guides are crafted to make learning programming languages
and technologies easier than you think, providing a structured, tutorial format
that will guide you through all the techniques involved.
Beginning
ASP.NET 4
in C# and VB
Foreword by Vishal R. Joshi, Lead Program Manager, Microsoft Web Platform & Tools
Get more out of
wrox.com
Programmer to Programmer

Interact
Take an active role online by participating in our
P2P forums @ p2p.wrox.com
Wrox Online Library
Hundreds of our books are available online
through Books24x7.com
Wrox Blox
Download short informational pieces and code
to keep you up to date and out of trouble!
Join the Community
Sign up for our free monthly newsletter at
newsletter.wrox.com
Browse

Ready for more Wrox? We have books and
e-books available on .NET, SQL Server, Java,
XML, Visual Basic, C#/ C++, and much more!
Contact Us.
We always like to get feedback from our readers. Have a book idea?
Need community support? Let us know by e-mailing
Related Wrox Books
Beginning Visual C# 2010
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 ASP.NET 4: in C# and VB
ISBN: 978-0-470-50220-4
Written by three highly recognized and regarded ASP.NET experts, this book provides all-encompassing coverage on ASP.NET 4 and
offers a unique approach of featuring examples in both C# and VB, as is the incomparable coverage of core ASP.NET. After a
fast-paced refresher on essentials such as server controls, the book delves into expert coverage of all the latest capabilities of
ASP.NET 4. You’ll learn site navigation, personalization, membership, role management, security, and more.
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 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.
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 Visual Studio 2010
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.
Visual Basic 2010 Programmer’s Reference
ISBN: 978-0-470-49983-2
Visual Basic 2010s 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.
Visual Studio 2010 and .NET 4 Six-in-One
ISBN: 978-0-470-49948-1
This comprehensive resource offers a single resource for all you need to know to get productive with .NET 4. It 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.
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 provides 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.
BEGINNING
ASP.NET 4: IN C# AND VB
FOREWORD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
INTRODUCTION xxvii
CHAPTER 1 Getting Started with ASP.NET 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
CHAPTER 2 Building an ASP.NET Web Site . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
CHAPTER 3 Designing Your Web Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
CHAPTER 4 Working with ASP.NET Server Controls 105
CHAPTER 5 Programming Your ASP.NET Web Pages 139
CHAPTER 6 Creating Consistent Looking Web Sites . . . . . . . . . . . . . . . . . . . . . . . . . 197

CHAPTER 7 Navigation 239
CHAPTER 8 User Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
CHAPTER 9 Validating User Input 297
CHAPTER 10 ASP.NET AJAX 331
CHAPTER 11 jQuery. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
CHAPTER 12 Introducing Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
CHAPTER 13 Displaying and Updating Data 433
CHAPTER 14 LINQ and the ADO.NET Entity Framework . . . . . . . . . . . . . . . . . . . . . . . 477
CHAPTER 15 Working with Data — Advanced Topics 529
CHAPTER 16 Security in Your ASP.NET 4 Web Site 579
CHAPTER 17 Personalizing Web Sites 619
CHAPTER 18 Exception Handling, Debugging, and Tracing . . . . . . . . . . . . . . . . . . . .655
CHAPTER 19 Deploying Your Web Site . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 697
APPENDIX A Exercise Answers 731
APPENDIX B Configuring SQL Server 2008 757
INDEX 777
502211ffirs.indd 1 2/19/10 9:58:33 AM
502211ffirs.indd 2 2/19/10 9:58:33 AM
Beginning
ASP.NET 4
502211ffirs.indd 3 2/19/10 9:58:33 AM
502211ffirs.indd 4 2/19/10 9:58:33 AM
Beginning
ASP.NET 4
in C# and VB
Imar Spaanjaars
502211ffirs.indd 5 2/19/10 9:58:34 AM
Beginning 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-50221-1
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 limi-
tation 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: 2009943646
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, and Wrox Programmer to Programmer are trademarks or regis-

tered 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.
502211ffirs.indd 6 2/19/10 9:58:34 AM
To my friends
502211ffirs.indd 7 2/19/10 9:58:34 AM
502211ffirs.indd 8 2/19/10 9:58:34 AM
ABOUT THE AUTHOR
IMAR SPAANJAARS graduated in Leisure Management at the Leisure Management School in the
Netherlands, but he quickly changed his career path into the Internet world.
After working in the Internet business at various web agencies for the past twelve years, he recently
started up his own company called De Vier Koeden (
www.devierkoeden.nl), a small Internet agency
specializing in consultancy and development of Internet and intranet applications with Microsoft
technologies such as ASP.NET 4.
Imar has written books on ASP.NET and Macromedia Dreamweaver, all published under the Wrox
brand. He is also one of the top contributors to the Wrox Community Forum at
p2p.wrox.com,
where he shares his knowledge with fellow programmers.
In 2008 and 2009, Imar received Microsoft’s Most Valuable Professional (MVP) award for his
contributions to the ASP.NET community.
Imar lives in Utrecht, the Netherlands, with his girlfriend, Fleur. You can contact him through his
personal web site at
or by e-mail at
502211ffirs.indd 9 2/19/10 9:58:34 AM
502211ffirs.indd 10 2/19/10 9:58:34 AM
ACQUISITIONS EDITOR
Paul Reese
PROJECT EDITOR
Brian Herrmann

TECHNICAL EDITOR
Michael J. Apostol
PRODUCTION EDITOR
Rebecca Anderson
COPY EDITOR
Kim Cofer
EDITORIAL DIRECTOR
Robyn B. Siesky
EDITORIAL MANAGER
Mary Beth Wakefield
ASSOCIATE DIRECTOR OF MARKETING
David Mayhew
PRODUCTION MANAGER
Tim Tate
VICE PRESIDENT AND EXECUTIVE GROUP
PUBLISHER
Richard Swadley
VICE PRESIDENT AND EXECUTIVE PUBLISHER
Barry Pruett
ASSOCIATE PUBLISHER
Jim Minatel
PROJECT COORDINATOR, COVER
Lynsey Stanford
COMPOSITOR
Craig Johnson, Happenstance Type-O-Rama
PROOFREADER
Josh Chase, Word One New York
INDEXER
Robert Swanson
COVER DESIGNER

Michael E. Trent
COVER IMAGE
© Nevin Giesbrecht/istockphoto
CREDITS
502211ffirs.indd 11 2/19/10 9:58:34 AM
502211ffirs.indd 12 2/19/10 9:58:34 AM
ACKNOWLEDGMENTS
JUST AS WITH MY PRIOR BOOKS, I really enjoyed writing this one. The process from an empty Word
document at the very beginning to a printed copy as the final result is a really interesting one. Along
the way, I discovered, understood and used a lot of the new features that ASP.NET 4 and Visual
Web Developer 2010 bring. Since this book is a major update on the previous edition — Beginning
ASP.NET 3.5 in C# and VB — I have been able to incorporate a lot of reader feedback into this edi-
tion. While working on this book, I went through the more than 450 threads in the book’s forum,
looking for feedback that could improve this edition. This allowed me to add clarification and more
detailed instructions where needed. If you have the previous edition and posted a question in the
Wrox forums: thanks for your valuable feedback; you’ve really helped to make this book better.
Besides my readers, I owe a lot to other people who helped me write this book.
First of all I’d like to thank Brian Herrmann for his editorial work. Just as before, it was a pleasure
to work with you! I also want to thank Michael J. Apostol for his work as a technical editor, and the
people from Wrox for their support and contributions to this book.
Another person I owe a lot to is my friend Anne Ward from Blue Violet, a UK-based web and graphic
design company. Anne has done most of the new designs used in this book and I highly appreciate her
input. Thanks again, Anne! The concert pictures you see in this book come from Nigel D. Nudds,
who kindly let me use pictures from his collection.
Finally, I would like to thank my good friends Joost and René and my lovely girlfriend Fleur for
their support during this project.
502211ffirs.indd 13 2/19/10 9:58:34 AM
502211ffirs.indd 14 2/19/10 9:58:34 AM
Contents
FOREWORD xxv

INTRODUCTION xxvii
GettinG started with asP.net 4 ChaPter 1: 1
Microsoft Visual Web Developer 2
Getting Visual Web Developer 3
Installing Visual Web Developer Express 3
Creating Your First ASP.NET 4 Web Site 5
An Introduction to ASP.NET 4 9
Understanding HTML 10
A First Look at ASP.NET Markup 14
A Tour of the IDE 15
The Main Development Area 15
Informational Windows 21
Customizing the IDE 22
Rearranging Windows 22
Modifying the Toolbox 23
Customizing the Document Window 25
Customizing Toolbars 26
Customizing Keyboard Shortcuts 26
Resetting Your Changes 27
The Sample Application 27
Practical Tips on Visual Web Developer 29
Summary 30
BuildinG an asP.net weB site 3ChaPter 2: 3
Creating Web Sites with VWD 2010 34
Dierent Project Types 34
Choosing the Right Web Site Template 35
Creating and Opening a New Web Site 37
Working with Files in Your Web Site 40
The Many File Types of an ASP.NET 4 Web Site 40
Adding Existing Files 44

Organizing Your Site 46
Special File Types 47
502211ftoc.indd 15
2/19/10 9:58:29 AM
xvi
CONTENTS
Working with Web Forms 47
The Dierent Views on Web Forms 47
Choosing between Code Behind and Pages with Inline Code 49
Adding Markup to Your Page 54
Connecting Pages 60
Practical Tips on Working with Web Forms 62
Summary 63
desiGninG Your weB PaGes 6ChaPter 3: 5
Why Do You Need CSS? 66
Problems of HTML Formatting 66
How CSS Fixes Formatting Problems 67
An Introduction to CSS 68
CSS—The Language 71
The Style Sheet 72
Adding CSS to Your Pages 84
Working with CSS in Visual Web Developer 87
Creating New Styles in External Style Sheets 87
Creating Embedded and Inline Style Sheets 92
Applying Styles 98
Managing Styles 99
Practical Tips on Working with CSS 102
Summary 103
workinG with asP.net server Controls 10ChaPter 4: 5
Introduction to Server Controls 106

A Closer Look at ASP.NET Server Controls 110
Defining Controls in Your Pages 110
Common Properties for All Controls 110
Types of Controls 113
Standard Controls 113
HTML Controls 126
Data Controls 127
Validation Controls 127
Navigation Controls 127
Login Controls 127
Ajax Extensions 127
WebParts 128
Dynamic Data 128
502211ftoc.indd 16
2/19/10 9:58:29 AM
xvii
CONTENTS
The ASP.NET State Engine 128
What Is State and Why Is It Important? 128
How the State Engine Works 129
Not All Controls Rely on View State 133
A Note about View State and Performance 134
Practical Tips on Working with Controls 135
Summary 136
ProGramminG Your asP.net weB PaGes 13ChaPter 5: 9
Introduction to Programming 140
Data Types and Variables 141
Converting and Casting Data Types 144
Using Arrays and Collections 146
Statements 151

Operators 152
Making Decisions 159
Loops 166
Organizing Code 170
Methods: Functions and Subroutines 170
The App_Code Folder 172
Organizing Code with Namespaces 176
Writing Comments 179
Object Orientation Basics 181
Important OO Terminology 182
Events 192
Practical Tips on Programming 194
Summary 195
CreatinG Consistent lookinG weB sites 19ChaPter 6: 7
Consistent Page Layout with Master Pages 198
Creating Master Pages 200
Creating Content Pages 201
Using a Centralized Base Page 207
An Introduction to the ASP.NET Page Life Cycle 208
Implementing the Base Page 210
Creating Reusable Page Templates 214
Themes 218
Dierent Types of Themes 219
Choosing Between Theme and StyleSheetTheme 219
Applying Themes 220
Extending Themes 224
Dynamically Switching Themes 226
502211ftoc.indd 17
2/19/10 9:58:29 AM
xviii

CONTENTS
Skins 232
Creating a Skin File 233
Named Skins 235
Disable Theming for Specific Controls 236
Practical Tips on Creating Consistent Pages 236
Summary 237
naviGation 23ChaPter 7: 9
Dierent Ways to Move around Your Site 240
Understanding Absolute and Relative URLs 240
Understanding Default Documents 244
Using the Navigation Controls 245
Architecture of the Navigation Controls 245
Examining the Web.sitemap File 246
Using the Menu Control 248
Using the TreeView Control 257
Using the SiteMapPath Control 261
Programmatic Redirection 263
Programmatically Redirecting the Client to a Dierent Page 263
Server-Side Redirects 266
Practical Tips on Navigation 268
Summary 269
user Controls 27ChaPter 8: 1
Introduction to User Controls 272
Creating User Controls 272
Adding User Controls to a Content Page or Master Page 276
Site-Wide Registration of User Controls 279
User Control Caveats 280
Adding Logic to Your User Controls 282
Creating Your Own Data Types for Properties 283

Implementing View State Properties 288
View State Considerations 294
Practical Tips on User Controls 294
Summary 295
validatinG user inPut 29ChaPter 9: 7
Gathering Data from the User 298
Validating User Input in Web Forms 299
Understanding Request Validation 316
502211ftoc.indd 18
2/19/10 9:58:29 AM
xix
CONTENTS
Processing Data at the Server 316
Sending E-mail from Your Web Site 317
Reading from Text Files 322
Practical Tips on Validating Data 328
Summary 329
asP.net aJaX 33ChaPter 10: 1
Introducing Ajax 332
Using ASP.NET AJAX in Your Projects 334
Creating Flicker-Free Pages 334
Providing Feedback to Users 340
The Timer Control 345
Using Web Services and Page Methods in Ajax Web Sites 346
What Are Web Services? 346
Creating Web Services 347
Using Web Services in Your Ajax Web Site 351
Introducing Page Methods 358
The Client-Side ASP.NET AJAX Library 361
This Is Just the Beginning 362

Practical Ajax Tips 363
Summary 364
JQuerY 36ChaPter 11: 7
An Introduction to jQuery 368
Choosing the Location for Your jQuery Reference 368
Dierent Ways to Include the jQuery Library 369
jQuery Syntax 373
jQuery Core 374
Selecting Items Using jQuery 374
Modifying the DOM with jQuery 382
CSS Methods 382
Handling Events 383
Miscellaneous jQuery Functionality 385
Common Mistakes When Working with jQuery 386
Eects with jQuery 391
jQuery and Extensibility 396
Practical Tips on jQuery 400
Summary 401
502211ftoc.indd 19
2/19/10 9:58:29 AM
xx
CONTENTS
introduCinG dataBases 40ChaPter 12: 3
What Is a Database? 404
Dierent Kinds of Relational Databases 405
Using SQL to Work with Database Data 405
Retrieving and Manipulating Data with SQL 407
Reading Data 408
Creating Data 417
Updating Data 418

Deleting Data 418
Creating Your Own Tables 421
Data Types in SQL Server 421
Understanding Primary Keys and Identities 422
Creating Relationships Between Tables 426
Practical Database Tips 430
Summary 431
disPlaYinG and uPdatinG data 43ChaPter 13: 3
Data Controls 433
Data-bound Controls 434
Data Source Controls 435
Other Data Controls 436
Data Source and Data-bound Controls Working Together 436
Displaying and Editing Data with GridView 436
Inserting Data with DetailsView 442
Storing Your Connection Strings in web.config 445
Filtering Data 446
Customizing the Appearance of the Data Controls 452
Configuring Columns or Fields of Data-bound Controls 453
Updating and Inserting Data 459
Using DetailsView to Insert and Update Data 459
Practical Tips for Displaying and Updating Data 473
Summary 474
linQ and the ado.net entitY Framework 47ChaPter 14: 7
Introducing LINQ 478
LINQ to Objects 479
LINQ to XML 479
LINQ to ADO.NET 479
Introducing the ADO.NET Entity Framework 480
Mapping Your Data Model to an Object Model 481

502211ftoc.indd 20
2/19/10 9:58:29 AM
xxi
CONTENTS
Introducing Query Syntax 487
Standard Query Operators 487
Shaping Data with Anonymous Types 491
Using Server Controls with LINQ Queries 496
Using Data Controls with the Entity Framework 496
A Few Notes about Performance 526
Practical LINQ and ADO.NET Entity Framework Tips 526
Summary 527
workinG with data — advanCed toPiCs 52ChaPter 15: 9
Formatting Your Controls Using Styles 530
An Introduction to Styles 531
Combining Styles, Themes, and Skins 535
Handling Events 539
The ASP.NET Page and Control Life Cycles Revisited 540
The ASP.NET Page Life Cycle and Events in Data Controls 545
Handling Errors that Occur in the Data Source Controls 550
Hand-Coding Data Access Code 554
Caching 565
Common Pitfalls with Caching Data 565
Dierent Ways to Cache Data in ASP.NET Web Applications 566
Practical Data Tips 575
Summary 576
seCuritY in Your asP.net 4 weB site 57ChaPter 16: 9
Introducing Security 580
Identity: Who Are You? 580
Authentication: How Can You Prove Who You Are? 580

Authorization: What Are You Allowed to Do? 580
An Introduction to the ASP.NET Application Services 581
Introducing the Login Controls 582
The Login Controls 587
Configuring Your Web Application 599
The Role Manager 603
Configuring the Role Manager 603
Managing Users with the WSAT 604
Configuring the Web Application to Work with Roles 608
Programmatically Checking Roles 612
Practical Security Tips 616
Summary 617
502211ftoc.indd 21
2/19/10 9:58:29 AM
xxii
CONTENTS
PersonalizinG weB sites 61ChaPter 17: 9
Understanding Profile 620
Configuring the Profile 621
Using the Profile 627
Other Ways of Dealing with Profile 645
Anonymous Identification 645
Cleaning Up Old Anonymous Profiles 646
Looking at Other Users’ Profiles 648
Practical Personalization Tips 651
Summary 651
eXCePtion handlinG, deBuGGinG, and traCinG 65ChaPter 18: 5
Exception Handling 656
Dierent Types of Errors 656
Catching and Handling Exceptions 658

Global Error Handling and Custom Error Pages 666
The Basics of Debugging 673
Tools Support for Debugging 677
Moving around in Debugged Code 677
Debugging Windows 677
Debugging Client-Side Script 684
Tracing Your ASP.NET Web Pages 688
Using the Standard Tracing Capabilities 688
Adding Your Own Information to the Trace 691
Tracing and Performance 694
A Security Warning 694
Practical Debugging Tips 694
Summary 695
dePloYinG Your weB site 69ChaPter 19: 7
Preparing Your Web Site for Deployment 698
Avoiding Hardcoded Settings 698
The web.config File 699
Expression Syntax 699
The WebConfigurationManager Class 700
Copying Your Web Site 706
Creating a Simple Copy of Your Web Site 707
Publishing Your Web Site 709
502211ftoc.indd 22
2/19/10 9:58:29 AM
xxiii
CONTENTS
Running Your Site under IIS 710
Installing and Configuring the Web Server 711
Installing and Configuring ASP.NET 714
Understanding Security in IIS 717

NTFS Settings for Planet Wrox 718
Troubleshooting Web Server Errors 721
Moving Data to a Remote Server 723
Using the Database Publishing Wizard 723
Recreating the Database 725
The Deployment Checklist 727
What’s Next 728
Summary 729
eXerCise answers 73aPPendiX a: 1
Chapter 1 731
Chapter 2 732
Chapter 3 733
Chapter 4 734
Chapter 5 735
Chapter 6 736
Chapter 7 737
Chapter 8 738
Chapter 9 739
Chapter 10 741
Chapter 11 743
Chapter 12 744
Chapter 13 745
Chapter 14 746
Chapter 15 749
Chapter 16 751
Chapter 17 752
Chapter 18 754
ConFiGurinG sQl server 2008 75aPPendiX B: 7
Configuring SQL Server 2008 757
Terminology and Concepts 758

Using SQL Server Management Studio 759
Enabling Remote Connections in SQL Server 760
Connecting Your Application to SQL Server 2008 764
502211ftoc.indd 23
2/19/10 9:58:29 AM

×