Tài liệu ASP.NET Web developer''''s Guide doc - Pdf 84

1 YEAR UPGRADE
BUYER PROTECTION PLAN
Mesbah Ahmed
Chris Garrett
Jeremy Faircloth
Chris Payne
DotThatCom.com
Wei Meng Lee
Series Editor
Jonothon Ortiz
Technical Editor
ASP.NET
Web Developer’s Guide

With more than 1,500,000 copies of our MCSE, MCSD, CompTIA, and Cisco
study guides in print, we continue to look for ways we can better serve the
information needs of our readers. One way we do that is by listening.
Readers like yourself have been telling us they want an Internet-based ser-
vice that would extend and enhance the value of our books. Based on
reader feedback and our own strategic plan, we have created a Web site
that we hope will exceed your expectations.
is an interactive treasure trove of useful infor-
mation focusing on our book topics and related technologies. The site
offers the following features:

One-year warranty against content obsolescence due to vendor
product upgrades. You can access online updates for any affected
chapters.

“Ask the Author” customer query forms that enable you to post
questions to our authors and editors.

production (collectively “Makers”) of this book (“the Work”) do not guarantee or warrant the results to be
obtained from the Work.
There is no guarantee of any kind, expressed or implied, regarding the Work or its contents.The Work is
sold AS IS and WITHOUT WARRANTY. You may have other legal rights, which vary from state to state.
In no event will Makers be liable to you for damages, including any loss of profits, lost savings, or other
incidental or consequential damages arising out from the Work or its contents. Because some states do not
allow the exclusion or limitation of liability for consequential or incidental damages, the above limitation
may not apply to you.
You should always use reasonable care, including backup and other appropriate precautions, when working
with computers, networks, data, and files.
Syngress Media®, Syngress®,“Career Advancement Through Skill Enhancement®,” and “Ask the Author
UPDATE®,”are registered trademarks of Syngress Publishing, Inc. “Mission Critical™,”“Hack Proofing™,”
and “The Only Way to Stop a Hacker is to Think Like One™” are trademarks of Syngress Publishing, Inc.
Brands and product names mentioned in this book are trademarks or service marks of their respective
companies.
KEY SERIAL NUMBER
001 ANVE48952P
002 WNBN9433ET
003 7BANL4P2WR
004 QNV984UTAP
005 KVAW939RE4
006 6JSE4FHU9W
007 4MAS8TYGF2
008 DAUTGFLRGT
009 2983K74SLF
010 VFR4MHY7Q2
PUBLISHED BY
Syngress Publishing, Inc.
800 Hingham Street
Rockland, MA 02370

Mary Ging, Caroline Hird, Simon Beale, Caroline Wheeler,Victoria Fuller, Jonathan
Bunkell, and Klaus Beran of Harcourt International for making certain that our
vision remains worldwide in scope.
Annabel Dent of Harcourt Australia for all their help.
David Buckland,Wendi Wong, Daniel Loh, Marie Chieng, Lucy Chong, Leslie Lim,
Audrey Gan, and Joseph Chan of Transquest Publishers for the enthusiasm with
which they receive our books.
Kwon Sung June at Acorn Publishing for his support.
Ethan Atkin at Cranbury International for his help in expanding the Syngress
program.
166_ASPNET_FM.qxd 11/26/01 1:40 PM Page v
vi
Contributors
Todd Carrico (MCDBA, MCSE) is a Senior Database Engineer for
Match.com. Match.com is a singles portal for the digital age. In addition
to its primary Web site, Match.com provides back-end services to AOL,
MSN, and many other Web sites in its affiliate program.Todd specializes
in design and development of high-performance, high-availability data
architectures primarily on the Microsoft technology. His background
includes designing, developing, consulting, and project management for
companies such as Fujitsu, Accenture, International Paper, and
GroceryWorks.com.Todd resides in Sachse,TX, with his wife and two
children.
Jeremy Faircloth (CCNA, MCSE, MCP+I, A+) is a Systems Analyst for
Gateway, Inc. In this position, he develops and maintains enterprise-wide
client/server and Web-based technologies. He also acts as a technical
resource for other IT professionals, using his expertise to help others
expand their knowledge. As a Systems Analyst with over 10 years of real-
world IT experience, he has become an expert in many areas of IT
including Web development, database administration, enterprise security,

Jorgensen and nLogix. Patrick holds a bachelor’s of Science degree from
the University of Washington, Bothell. Patrick lives in Puyallup,WA with
his wife Angela.
David Jorgensen (MCP) is an Instructor at North Seattle Community
College, University of Washington Extension campus, and Puget Sound
Centers. He is also developing courses for Seattle Vocational Institute,
which teach .NET and Web development to the underprivileged in the
Seattle area. David also provides internship opportunities through his
company DotThatCom.com, which does online sample classes and chap-
ters of books. David holds a bachelor’s degree in Computer Science from
St. Martin’s College and resides in Puyallup,WA with his wife Lisa and
their two sons Scott and Jacob.
Adam Sills is an Internet Programmer at GreatLand Insurance, a small
insurance company parented by Kemper Insurance. He works in a small
IT department that focuses on creating applications to expedite business
processes and manage data from a multitude of locations. Previously, he
had a small stint in consulting and also worked at a leading B2B
166_ASPNET_FM.qxd 11/26/01 1:40 PM Page vii
viii
eCommerce company designing and building user interfaces to interact
with a large-scale enterprise eCommerce application.Adam’s current
duties include building and maintaining Web applications, as well as
helping to architect, build, and deploy new Microsoft .NET technologies
into production use. Adam has contributed to the writing of a number of
books for Syngress and is an active member of a handful of ASP and
ASP.NET mailing lists, providing support and insight whenever he can.
Chris Garrett is the Technical Manager for a large European Web
agency. He has been working with Internet technologies since 1994 and
has provided technical and new media expertise for some of the world’s
biggest brands. Chris lives in Yorkshire, England, with his wife Clare and

The code files for each chapter are located in a “chXX” directory. For example, the
files for Chapter 8 are in ch08.Any further directory structure depends on the pro-
jects that are presented within the chapter.
Chapters 4, 6, and 9 contain code that apply to the situations described in their
sections.This code will be extremely useful for understanding and enhancing the way
you use ASP.NET. Specifically, Chapter 4 has various examples on dealing with the
internal configuration of ASP.NET while Chapter 6 deals with how to optimize the
various caching methods available through ASP.NET and Chapter 9 contains code
on how to work with the debugging system of .NET with ASP.NET.
Chapters 3 and 8 contain code that deal with improved technologies in
ASP.NET. Chapter 3 discusses examples on how to work with ASP Server Controls
while Chapter 8 deals with a concise introduction to what XML is and how XML
affects .NET.
Chapters 7, 11, 12, and 13 contain low-to-heavy duty applications, exactly in that
order. Chapter 7 will introduce you to a sample application that deals with an address
book, from start to finish.This example code will also introduce you to how code
looks and operates in ASP.NET. Chapter 11, our XML.NET Guestbook, will show
you how XML in .NET can easily be worked with by using the standard classes
within ADO.NET, bridging the gap between XML and ADO. Chapters 12 and 13
take XML and ADO to the next level by introducing a Shopping Cart (Chapter 11)
and a Message Board (Chapter 13). Both applications in Chapters 12 and 13 require
an SQL Server backend, but either of these databases can be easily converted to an
Access database.
Look for this CD icon to obtain files used
in the book demonstrations.
About the CD
166_ASPNET_FM.qxd 11/26/01 1:40 PM Page x
Contents
xi
Foreword xxv

ASP was a hit-and-miss
affair, usually forcing the
developer to add
Response.Write
statements through the
code until he or she found
the failure point. ASP.NET
introduces much better
debugging, thanks to the
.NET Framework and
Common Language
Runtime (CLR).
166_ASPNET_toc.qxd 11/27/01 1:13 PM Page xi
xii Contents
Upgrading from Classic ASP 26
Taking Security Precautions 28
Summary 29
Solutions Fast Track 29
Frequently Asked Questions 32
Chapter 2 ASP.NET Namespaces 35
Introduction 36
Reviewing the Function of Namespaces 36
Using Namespaces 37
Using the Microsoft.VisualBasic Namespace 38
Understanding the Root Namespace: System 38
Supplied Functionality 38
Integral Numbers 39
Floating-Point Numbers 39
Dates 40
Strings 40

language, such as VB.NET
or C#.
166_ASPNET_toc.qxd 11/27/01 1:13 PM Page xii
Contents xiii
Chapter 3 ASP Server Controls 61
Introduction 62
Major Features of ASP.NET Server Controls 62
Collecting Data Using HTML Forms 63
Server-Side Processing in ASP.NET 65
A Simple Application Using
Conventional HTML Controls 66
A Simple Application Using ASP Server
Controls 68
Mapping Server Controls and Preserving
Their States 69
Including Scripts in an .aspx File 69
Loading a List Box via Script 70
Using the IsPostBack Property of a Page 72
AutoPostBack Attributes of Server Controls 73
Structure of an ASP.NET Web Form 75
Page Directives 76
The Order of Event Execution 77
Code-Behind versus In-Page Coding 77
Using Code-Behind without Compilation 79
Using Code Behind with Compilation 81
Using VS.Net for Developing a Web
Application 84
Using HTML Server Controls 87
Using the HtmlAnchor Control 88
Using the HtmlTable Control 88

Using Labels, TextBoxes, RadioButtons,
CheckBoxes, and DropDownLists 103
Using the ListControl Abstract Class 106
Using HyperLink Controls 110
Binding a ListControl to an ArrayList 111
Validation Controls 113
The RequiredFieldValidator Control 114
The RegularExpressionValidator Control 115
The CompareValidator Control 117
The RangeValidator Control 118
The CustomValidator Control 118
CustomValidator with Explicit
Client-Side Validation Function 120
Displaying the Error Message with Style 122
The ValidationSummary Control 123
Validating Patterned Strings, Passwords,
and Dates 126
</form></body></html> The
Databound ListControls Family 130
Using the Repeater Server Control 132
Using the DataList Control 139
Using the DataGrid Control 144
Providing Paging in DataGrid 152
Navigating to a Selected Page 154
Providing Data Editing Capability in
a DataGrid Control 157
Creating Custom ASP Server User Controls 161
Creating a Simple Web User Control 161
Exposing Properties of a User Control 163
Developing the Payroll User Control 164

Mapping Requests Using the
<httpHandlers> Tag 192
Configuring HTTP Modules
Using the <httpModules> Tag 193
Setting Runtime Options
Using the <httpRuntime> Tag 194
Setting Process Model Options
Using the <processModel> Tag 195
Configuring the Session State
Using the <sessionState> Tag 200
Configuring Request Modules Using
the <webRequestModule> Tag 202
SECURITY ALERT!
With the standard
ASP.NET
machine.config file, all
configuration files are
secured and cannot be
downloaded by a
client system. This
allows for some pro-
tection of critical infor-
mation such as user
IDs and passwords for
DSN sources, but keep
in mind that any
system can be hacked
with enough time and
effort. Always keep
security in mind when

Understanding Application State 232
Using Application State 232
Application Cache Object 233
Static Variables 234
State Example 234
Using Application Events 236
Supported Application Events 236
More Events 237
Working with Application Events 238
Threading Use 239
Working with
Application Events
To use application events
in your project, you must
do the following:

Create a Web
application folder using
the MMC.

Create a file called
Global.asax in the
directory you marked
as an application.

Within the Global.asax,
enter script tags with
the language you are
using (e.g., VB).


Using the cache.add and cache.insert
Methods 285
Using the Dependency Option 285
Using the Expiration Policy Option 287
Using the Priority Options 288
Using the CacheItemRemovedCallback
Delegate 289
</HTML>Using the Cache.Remove
Method 292
Advantages of Using Data Caching 292
Best Uses for Caching 293
Output Caching 294
Fragment Caching 294
Data Caching 294
Answers to Your
Frequently Asked
Questions
Q:
I have been asked to
migrate an application
from ASP to ASP.NET.
In the ASP application,
several third-party
utilities have been used
to provide for caching.
Should I use these or
use ASP.NET’s internal
caching?
A:
Use ASP.NET’s caching

Updating Data in a Database: Exercise 335
Deleting from a Database: Exercise 339
Summary 342
Solutions Fast Track 343
Frequently Asked Questions 345
Frequently Asked Questions 345
Chapter 8 Using XML in the
.NET Framework 347
Introduction 348
An Overview of XML 348
What Does an XML Document Look Like? 349
Creating an XML Document 350
Creating an XML Document
in VS.NET XML Designer 351
Components of an XML Document 352
Well-Formed XML Documents 355
The tblAddress Layout
166_ASPNET_toc.qxd 11/27/01 1:13 PM Page xviii
Contents xix
Schema and Valid XML Documents 356
Structure of an XML Document 360
Processing XML Documents Using .NET 361
Reading and Writing XML Documents 362
Storing and Processing XML Documents 363
Reading and Parsing Using the
XmlTextReader Class 364
Parsing an XML Document: 365
Navigating through an XML Document
to Retrieve Data 367
Writing an XML Document Using the

frequently used ones are
as follows:

Declaration

Comment

Schema or Document
Type Definition (DTD)

Elements

Root Element

Attributes
166_ASPNET_toc.qxd 11/27/01 1:13 PM Page xix
xx Contents
Transforming an XML Document
into Another XML Document 400
Working with XML and Databases 405
Creating an XML Document
from a Database Query 406
Reading an XML Document into a DataSet 408
Summary 410
Solutions Fast Track 410
Frequently Asked Questions 414
Chapter 9 Debugging ASP.NET 417
Introduction 418
Handling Errors 418
Syntax Errors 419

mode:
sortByCategory
or sortByTime.
166_ASPNET_toc.qxd 11/27/01 1:13 PM Page xx
Contents xxi
Chapter 10 Web Services 441
Introduction 442
Understanding Web Services 443
Communication between Servers 448
.asmx Files 450
WSDL 455
Using XML in Web Services 460
An Overview of the System.Web.Services
Namespace 461
The System.Web.Services.Description
Namespace 461
The System.Web.Services.Discovery
Namespace 461
The System.Web.Services.Protocols
Namespace 462
Type Marshalling 464
Using DataSets 466
Summary 469
Solutions Fast Track 469
Frequently Asked Questions 471
Chapter 11 Creating an XML.NET
Guestbook 473
Introduction 474
Functional Design Requirements of the XML
Guestbook 475

Shopping Cart 501
Introduction 502
Setting Up the Database 502
Setting Up the Table “Books” 505
Setting Up the Table “Categories” 505
Setting Up the Table “Customer” 505
Setting Up the Table “Orders” 505
Setting Up the Table “BookOrders” 506
Creating an Access Database 506
SQL Server Database 510
Creating the Stored Procedures 512
Creating the Web Services 518
Overview of the Book Shop Web Services 518
Creating the Data Connection 520
Creating a Web Service 521
Testing a Web Service 527
Using WSDL Web References 531
Building the Site 533
Site Administration 533
Creating the Administration Login
(adminLogin.aspx) 535
Creating the Administrator Page
(adminPage.aspx) 537
Retrieving the Data: Creating the
getBooks.AllBooks Web Method 537
Displaying the Data: Binding a
DataGrid to the DataSet 540
Adding New Books to the Database:
Creating the allBooks.addItem We b
Method 541

Creating an ADOCatalog 547
Creating the BookCatalog Class 548
Creating the CreateSummaryTable
Method 549
Creating the InitCatalog Method 550
Creating the Catalog Method 550
Creating the catalogItemDetails,
catalogRange, and catalogByCategory
Methods 550
Creating the catalogRangeByCategory
Method 551
Building an XMLCart 553
Creating the User Interface 556
Creating the start.aspx Page 556
Rendering the Catalog 558
Rendering the Cart 559
Creating the Code 559
Summary 562
Solutions Fast Track 562
Frequently Asked Questions 566
Chapter 13 Creating a Message
Board with ADO and XML 567
Introduction 568
Setting Up the Database 568
MSAccess Database 569
SQL Server Database 572
Designing Your Application 576
Designing Your Objects 579
Creating Your Data Access Object 579
166_ASPNET_toc.qxd 11/27/01 1:13 PM Page xxiii

well-formed way? The first
and most important step
is to break down what you
know you want your
application to do, analyze
those tasks, and then
extract the important
parts.
166_ASPNET_toc.qxd 11/27/01 1:13 PM Page xxiv


Nhờ tải bản gốc
Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status