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

Apress beginning visual web developer 2005 express from novice to professional dec 2005 ISBN 1590594827 pdf

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 (14.79 MB, 353 trang )


Delorme.book Page i Tuesday, November 15, 2005 11:40 AM

Beginning Visual Web
Developer 2005 Express
From Novice to Professional

■■■

Paul Sarknas with Rick Delorme


Delorme.book Page ii Tuesday, November 15, 2005 11:40 AM

Beginning Visual Web Developer 2005 Express: From Novice to Professional
Copyright © 2006 by Paul Sarknas and Rick Delorme
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.
ISBN (pbk): 1-59059-482-7
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence
of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark
owner, with no intention of infringement of the trademark.
Lead Editor: Ewan Buckingham
Technical Reviewer: Mark Horner
Editorial Board: Steve Anglin, Dan Appleman, Ewan Buckingham, Gary Cornell, Tony Davis,
Jason Gilmore, Jonathan Hassell, Chris Mills, Dominic Shakeshaft, Jim Sumser
Project Manager: Sofia Marchant
Copy Edit Manager: Nicole LeClerc
Copy Editor: Freelance Editorial Services


Assistant Production Director: Kari Brooks-Copony
Production Editor: Katie Stence
Compositor: Pat Christenson
Proofreader: Elizabeth Berry
Indexer: John Collin
Artist: April Milne
Cover Designer: Kurt Krames
Manufacturing Director: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor,
New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail , or
visit .
For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA
94710. Phone 510-549-5930, fax 510-549-5939, e-mail , or visit .
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 in the Source Code section.


Delorme.book Page iii Tuesday, November 15, 2005 11:40 AM

I would like to dedicate this work to my family in appreciation
for all their help and support over the years.
Paul Sarknas

I would like to dedicate this work to my two beautiful children, Jaxen and Kendyl,
and to my amazing wife, Jenn, without whom none of this would have been possible
because she is my anchor.
Richard Delorme



Delorme.book Page iv Tuesday, November 15, 2005 11:40 AM


Delorme.book Page v Tuesday, November 15, 2005 11:40 AM

Contents at a Glance
About the Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii

■CHAPTER 1

Introducing Visual Web Developer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

■CHAPTER 2

The Development Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

■CHAPTER 3

Introducing SQL Server Express . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

■CHAPTER 4

Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

■CHAPTER 5

Master Pages, Themes, and Skins . . . . . . . . . . . . . . . . . . . . . . . . . . . 101


■CHAPTER 6

Working with Data Using ADO.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . 119

■CHAPTER 7

Managing Site Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

■CHAPTER 8

Localization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169

■CHAPTER 9

Personalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189

■CHAPTER 10

Administration and Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215

■CHAPTER 11

Securing Websites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235

■CHAPTER 12

Debugging Your Website . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269

■CHAPTER 13


Deployment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291

■CHAPTER 14

Post Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307

■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321

v


Delorme.book Page vi Tuesday, November 15, 2005 11:40 AM


Delorme.book Page vii Tuesday, November 15, 2005 11:40 AM

Contents
About the Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xv
About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii

■CHAPTER 1

Introducing Visual Web Developer. . . . . . . . . . . . . . . . . . . . . . . . . .

1

What Is ASP.NET? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Visual Web Developer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Visual Web Developer vs. Visual Studio . . . . . . . . . . . . . . . . . . . . . . . . 2

Installing Visual Web Developer 2005 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Principles of Object-Oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . . 7
Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Your First Web Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Building Web Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Web Application Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
ASP.NET Runtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

■CHAPTER 2

The Development Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . .

21

Main Menu and Toolbars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
File Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Edit Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
View Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Website Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Build and Debug Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Tools Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Window Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Help Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

21
22
22
24
24

24
25
26
26

vii


Delorme.book Page viii Tuesday, November 15, 2005 11:40 AM

viii

■C O N T E N T S

■CHAPTER 3

Dockable Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Solution Explorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Properties Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Database Explorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Output Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Error List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Task List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Find Results View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Class View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Code Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Code-Beside . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
IntelliSense . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Inserting Code Snippets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Environment Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Projects and Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Text Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Database Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

28
29
31
33
35
35
35
36
37
38
38
38
40
41
41
42
42
43
43
43
43


Introducing SQL Server Express. . . . . . . . . . . . . . . . . . . . . . . . . . . . .

45

SQL Server Express . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
What’s Under the Hood? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SQL Server Express vs. SQL Server 2005. . . . . . . . . . . . . . . . . . . . . .
SQL Server Express Security Features . . . . . . . . . . . . . . . . . . . . . . . .
SQL Server Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
What Is a Database in SQL Server? . . . . . . . . . . . . . . . . . . . . . . . . . . .
Database Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using T-SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SQL Express Management Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Express Manager. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Installing Express Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Working with the Command Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Books Online . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Visual Web Developer Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Connecting to a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating Database Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

46
46
47
49
50
50
51
53

56
56
56
61
65
65
66
69
76


Delorme.book Page ix Tuesday, November 15, 2005 11:40 AM

■C O N T E N T S

■CHAPTER 4

Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

77

Standard Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
TextBox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
LinkButton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ImageButton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
HyperLink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
DropDownList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ListBox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

CheckBox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CheckBoxList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
RadioButton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
RadioButtonList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ImageMap. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
BulletedList. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
HiddenField . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Literal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Calendar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
AdRotator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
FileUpload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Xml. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
MultiView and View. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
PlaceHolder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Substitution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Data Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
GridView . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
DataList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
DetailsView . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
FormView . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Repeater . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SqlDataSource . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
AccessDataSource . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ObjectDataSource . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XmlDataSource . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SiteMapDataSource . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


78
79
79
79
79
79
79
79
79
79
80
80
80
80
80
80
80
80
80
81
81
81
81
81
81
81
81
81
84

84
84
84
84
85
85
85
85
85
85

ix


Delorme.book Page x Tuesday, November 15, 2005 11:40 AM

x

■C O N T E N T S

Validation Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
RequiredFieldValidator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
RangeValidator. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
RegularExpressionValidator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
CompareValidator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
CustomValidator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
ValidationSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Login and Security Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Login . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
LoginView . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

PasswordRecovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
LoginStatus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
LoginName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
CreateUserWizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
ChangePassword. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Navigation Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
SiteMapPath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
TreeView . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Custom Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100

■CHAPTER 5

Master Pages, Themes, and Skins. . . . . . . . . . . . . . . . . . . . . . . .

101

Master Pages and Content Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Themes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Adding a Theme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Applying a Theme at the Page Level . . . . . . . . . . . . . . . . . . . . . . . . .
Applying a Theme at the Application Level . . . . . . . . . . . . . . . . . . . .
Skins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating a Skin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

101
110
110

112
113
115
115
117


Delorme.book Page xi Tuesday, November 15, 2005 11:40 AM

■C O N T E N T S

■CHAPTER 6

■CHAPTER 7

■CHAPTER 8

Working with Data Using ADO.NET . . . . . . . . . . . . . . . . . . . . . . .

119

Data Access Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Data Access Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Data Providers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Data Stores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Web Application Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ASP.NET Data Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Data Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


119
120
120
120
120
121
130
133

Managing Site Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

135

Building the Site Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Web Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Programming with the Site Navigation API . . . . . . . . . . . . . . . . . . . . . . . .
Site Navigation Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Modifying Provider Data Returned . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

135
140
147
152
162
168

Localization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

169


Your Preferred Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using Automatic Browser Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Resource Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Changing the Language Programmatically . . . . . . . . . . . . . . . . . . . . . . . .
Localizing Static Content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

170
173
175
180
187
187

xi


Delorme.book Page xii Tuesday, November 15, 2005 11:40 AM

xii

■C O N T E N T S

■CHAPTER 9

■CHAPTER 10

■CHAPTER 11


Personalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

189

Web Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Web Part Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
User Profiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Profile Schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Providers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Accessing User Profiles in Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Themes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Theme Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Changing the Theme at Runtime . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

189
190
202
202
204
204
205
206
209
213

Administration and Configuration . . . . . . . . . . . . . . . . . . . . . . . .

215


Configuration Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
How Does It Work? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Configuration Management API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Administration Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Web Site Administration Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ASP.NET Microsoft Management Console Snap-In . . . . . . . . . . . . .
Command-Line Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

215
216
219
230
230
231
232
233

Securing Websites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

235

Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Windows Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Forms Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Passport Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Membership and Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Membership Provider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating a New User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
User Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Deleting Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Locking a User Account . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Roles Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

235
236
239
245
245
246
251
257
260
261
262


Delorme.book Page xiii Tuesday, November 15, 2005 11:40 AM

■C O N T E N T S

■CHAPTER 12

■CHAPTER 13

Security Web Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Login . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
LoginName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
LoginStatus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
LoginView . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

PasswordRecovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ChangePassword. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

264
264
265
265
265
265
266
267

Debugging Your Website . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

269

Enabling Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Inserting a Breakpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Navigation During Break Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Debugging Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Quick Watch Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Watch Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Locals Window. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Immediate Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Call Stack Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Tracing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Tracing at the Page Level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Tracing at the Application Level . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Custom Trace Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

269
271
271
273
277
277
278
279
280
282
283
283
287
288
289

Deployment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

291

Deployment Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XCOPY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Copy Web Site Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
In-Place Compilation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Precompilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


291
291
296
299
300
300
305

xiii


Delorme.book Page xiv Tuesday, November 15, 2005 11:40 AM

xiv

■C O N T E N T S

■CHAPTER 14

Post Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

307

Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Caching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SQL Server Caching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Output Caching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


307
309
309
318
319

■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321


Delorme.book Page xv Tuesday, November 15, 2005 11:40 AM

About the Authors

■PAUL SARKNAS currently serves as the president of his own consulting
company, Sarknasoft Solutions LLC, which provides enterprise solutions
to a wide array of companies that utilize the .NET platform. Sarknas
specializes in C#, ASP.NET, and SQL Server. He works intimately with all
aspects of software, including planning, gathering, designing, architecting,
developing, testing, and deploying.
Sarknas has worked with Microsoft technologies for over eight years
and has used .NET since its conception. Along with authoring and technical
reviewing for Apress, Sarknas has also co-authored for WROX Press.
Sarknas may be contacted via his consulting company’s website, ,
and he welcomes questions and feedback of any kind.

■RICHARD DELORME is a technical consultant. He lives in Ottawa, Ontario, Canada. He has an
MCSD for Microsoft .NET. He is working on enterprise applications for the postal industry.

xv



Delorme.book Page xvi Tuesday, November 15, 2005 11:40 AM


Delorme.book Page xvii Tuesday, November 15, 2005 11:40 AM

About the Technical Reviewer

■MARK HORNER is principal enterprise architect and .NET application
consultant with Torville Software. He is a 25-year veteran of the industry and
has worked with a host of blue-chip organizations, including Citibank, NRMA
Insurance, ANZ Banking Group, Unilever, Hewlett-Packard, British Aerospace,
and CPA Australia. You can contact him at

xvii


Delorme.book Page xviii Tuesday, November 15, 2005 11:40 AM


Delorme.book Page 1 Friday, November 11, 2005 12:29 PM

CHAPTER 1
■■■

Introducing Visual Web
Developer
W

elcome to Microsoft’s Visual Web Developer (VWD)! This book most likely attracted you

because you are new to programming and want to know how to build a web application. You
have come to the right place. This book will guide you through the necessary steps and teach
you all the relevant information you need to build solid web applications with VWD using
ASP.NET 2.0. As the book progresses, you will gain a deeper understanding of the technologies
involved. Throughout this book, we thoroughly examine all aspects of building websites with
ASP.NET 2.0, from building your first simple web page to building your first dynamic web
application and leveraging the starter kits. By the end of this book, you will be off to the races.
We begin with the following topics:
• What ASP.NET is and how it works
• How to install VWD
• How the Internet works
• The principles of object-oriented programming
• How to build and run your first web application

What Is ASP.NET?
In 2001, Microsoft released Microsoft .NET, which represents a paradigm shift in the way web
applications are built. For the purposes of this book, you only need to know that .NET is a platform that provides the framework for ASP.NET, which provides a simple development model
for building highly interactive web applications. Although you can build static websites using
ASP.NET, its real power comes from its ability to manage user interactions from the web page
all the way back to a data store without the need to know client-side scripting. With ASP.NET,
a lot of the heavy lifting occurs on the server, thus reducing the amount of client-side scripting
a programmer needs to know. However, ASP.NET still supports all client-side scripting, so
those of you who are more familiar with it can definitely leverage it where appropriate. When
users interact with an ASP.NET web page, they send a processing request to the server, where
it is executed and returned back to them. One of the beautiful things about ASP.NET is that you
do not need to know much more than what you’ve just read to get it up and running. However,
1


Delorme.book Page 2 Friday, November 11, 2005 12:29 PM


2

CHAPTER 1 ■ INTRODUCING VISUAL WEB DEVELOPER

if your curiosity is aroused and you would like to read more about the .NET Framework, take
a look at some of these well-known resources: and, of course,
, an extensive library of resources from the Microsoft Developer
Network (MSDN). We will get back to building applications with ASP.NET 2.0 shortly, but for
now, let’s talk briefly about VWD.

Visual Web Developer
You may be wondering where Visual Web Developer comes into play. All the way back to the
old versions of Visual Basic, ASP, and the like, it was always possible to build applications using
something like Notepad. You would simply type up your code files in any text editor, save them
to disk, and then compile them on the command line. The command line is a non-Windowsbased utility. If you had any errors, you would open the file, fix them, and then go back to the
command line and try again. This was a tedious and time-consuming way to build any application. If you are like me, you like results and you like them fast. This is where the power of
VWD comes into play. It provides a nice graphical user interface (GUI) that provides an
Integrated Development Environment (IDE) to wrap up all the details we just discussed. An
IDE integrates all kinds of different development tools into one environment. Here this environment is the Visual Web Developer. There is no need to go to the command line for anything.
In addition simply to camouflaging the compiling of your applications and running them in
your favorite browser, the IDE also provides a wide array of productivity enhancements, such
as IntelliSense, on-the-fly code validation, an assortment of wizards that write code, and elements to create and manage databases. You may be asking, If all this functionality is provided
by VWD, why would anyone ever use Visual Studio? Let’s quickly answer that question now.

Visual Web Developer vs. Visual Studio
For all intents and purposes, there is no significant difference between Visual Studio .NET and
Visual Web Developer. Visual Studio is the full entourage of Microsoft’s Visual Programming
suite, including VB .NET, C#, Windows Forms, and, of course, ASP.NET. Visual Studio is heavy.
A lot of its features geared toward enterprise development are irrelevant for our purposes here.

Microsoft released a suite of smaller development tools known as the Express versions. There
is an Express development tool representing each aspect of Visual Studio. So VWD is just about
everything you need from Visual Studio to build web applications, without all the extra baggage. And, of course, VWD has a lower price tag, much lower. Although there are some subtle
differences, we will not bore you with them here; we will see that they are relatively unimportant. Next let’s get going and install VWD so we can start building some cool web applications.

Installing Visual Web Developer 2005
Installing applications is easier than ever, and VWD is not an exception. In this section, we will
quickly work through installing the development environment so you can get to the really fun
stuff. For the purposes of this book, you need to have Visual Web Developer 2005 and SQL
Server Express 2005 (discussed in Chapter 3). To set it up, double-click the installation file
(.msi). When the installation starts, you will receive a series of dialogs. The installation begins
with a welcome screen as shown in Figure 1-1.


Delorme.book Page 3 Friday, November 11, 2005 12:29 PM

CHAPTER 1 ■ INTRODUCING VISUAL WEB DEVELOPER

Figure 1-1. Visual Web Developer setup welcome page
Click the Next button. You see the standard Microsoft End User License Agreement
(EULA) form (Figure 1-2). Read through the licensing agreement, and if you agree, click the
Accept button.

Figure 1-2. Accepting the End User License Agreement

3


Delorme.book Page 4 Friday, November 11, 2005 12:29 PM


4

CHAPTER 1 ■ INTRODUCING VISUAL WEB DEVELOPER

If you accept the EULA, you will be presented with your installation options (Figure 1-3).

Figure 1-3. Visual Web Developer installation options
With the Visual Studio Express products, your installation options are limited. You need
SQL Server Express Edition and also the MSDN Express Library. To speed up the installation,
leave J# unchecked. It is implied that you want Visual Web Developer. Ensure that the two
check boxes are selected as in Figure 1-3. Click Next to proceed to the next step of the
installation.
As shown in Figure 1-4, you may now select the location where you want the installation
to copy all of the necessary files and lists. A summary of the options you have selected to install
along with the necessary disk space requirements appears. At a minimum, your list should
match my list in Figure 1-4 because all these components are required in the rest of the book.
If you are satisfied with the selected installation location, click Install.
Once you click Install, you see the installation progress screen (Figure 1-5). This screen lets
you know how the installation is moving along, with green check marks indicating which parts
have completed and the red arrow showing what portion of the installation is in progress.


Delorme.book Page 5 Friday, November 11, 2005 12:29 PM

CHAPTER 1 ■ INTRODUCING VISUAL WEB DEVELOPER

Figure 1-4. Installation location and selected products summary

Figure 1-5. Installation progress


5


Delorme.book Page 6 Friday, November 11, 2005 12:29 PM

6

CHAPTER 1 ■ INTRODUCING VISUAL WEB DEVELOPER

Once the installation is complete, you see the final page of the installation wizard
(Figure 1-6), which informs you of the status of the installation and whether or not there
were any errors. A link to a Windows update is provided so you can check for any updates to
the software and your computer environment in general. You are also required to activate
your software. If you do not, it will cease to function after 30 days. Click the Exit button and
verify that VWD is installed.

Figure 1-6. The Visual Web Developer installation is complete.
Go to your Start menu and open Programs. You should see a new item for Visual Web
Developer 2005 Express Edition. Click on this item to open VWD. You are now looking at the
Visual Web Developer Integrated Development Environment (Figure 1-7). In Chapter 2, we
explore this environment in great detail.
You now have a fully enabled development environment to help you build cool web applications. Why wait any longer? Let’s dive in. In this next section, you will build your first web
application. We introduce important concepts briefly as we work through this sample; however, if you are unclear about something or it is not explained fully here, don’t worry. It will all
be covered as you work through the more advanced examples throughout the book.


×