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

Professional ASP.NET 3.5 in C# and Visual Basic Part 3 pptx

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 (100.91 KB, 10 trang )

Evjen ftoc.tex V2 - 01/28/2008 5:00pm Page xxiv
Contents
Tracing from Components 1113
Trace Forwarding 1114
TraceListeners 1114
Diagnostic Switches 1119
Web Events 1121
Debugging 1122
What’s Required 1123
IIS versus ASP.NET Development Server 1124
Starting a Debugging Session 1125
New Tools to Help You with Debugging 1128
Client-side Javascript Debugging 1131
SQL Stored Proc Debugging 1134
Exception and Error Handling 1134
Handling Exceptions on a Page 1135
Handling Application Exceptions 1136
Http Status Codes 1137
Summary 1138
Chapter 25: File I/O and Streams 1139
Working with Drives, Directories, and Files 1140
The DriveInfo Class 1140
The Directory and DirectoryInfo Classes 1143
File and FileInfo 1149
Working with Paths 1154
File and Directory Properties, Attributes, and Access Control Lists 1158
Reading and Writing Files 1166
Streams 1167
Readers and Writers 1171
Compressing Streams 1176
Working with Serial Ports 1181


Network Communications 1182
WebRequest and WebResponse 1183
Sending Mail 1189
Summary 1190
Chapter 26: User and Server Controls 1193
User Controls 1194
Creating User Controls 1194
Interacting with User Controls 1196
Loading User Controls Dynamically 1198
xxiv
Evjen ftoc.tex V2 - 01/28/2008 5:00pm Page xxv
Contents
Server Controls 1203
WebControl Project Setup 1204
Control Attributes 1209
Control Rendering 1210
Adding Tag Attributes 1214
Styling HTML 1217
Themes and Skins 1220
Adding Client-Side Features 1222
Detecting and Reacting to Browser Capabilities 1231
Using ViewState 1234
Raising PostBack Events 1238
Handling PostBack Data 1242
Composite Controls 1244
Templated Controls 1247
Creating Control Design-Time Experiences 1254
Summary 1273
Chapter 27: Modules and Handlers 1275
Processing HTTP Requests 1275

IIS 5/6 and ASP.NET 1275
IIS 7 and ASP.NET 1276
ASP.NET Request Processing 1277
HttpModules 1278
HttpHandlers 1289
Summary 1295
Chapter 28: Using Business Objects 1297
Using Business Objects in ASP.NET 3.5 1297
Creating Precompiled .NET Business Objects 1298
Using Precompiled Business Objects in Your ASP.NET Applications 1301
COM Interop: Using COM Within .NET 1302
The Runtime Callable Wrapper 1303
Using COM Objects in ASP.NET Code 1304
Error Handling 1309
Deploying COM Components with .NET Applications 1312
Using .NET from Unmanaged Code 1314
The COM-Callable Wrapper 1314
Using .NET Components Within COM Objects 1316
Early versus Late Binding 1320
xxv
Evjen ftoc.tex V2 - 01/28/2008 5:00pm Page xxvi
Contents
Error Handling 1320
Deploying .NET Components with COM Applications 1322
Summary 1324
Chapter 29: Building and Consuming Services 1325
Communication Between Disparate Systems 1325
Building a Simple XML Web Service 1327
The WebService Page Directive 1328
Looking at the Base Web Service Class File 1329

Exposing Custom Datasets as SOAP 1330
The XML Web Service Interface 1333
Consuming a Simple XML Web Service 1336
Adding a Web Reference 1336
Invoking the Web Service from the Client Application 1338
Transport Protocols for Web Services 1341
HTTP-GET 1342
HTTP-POST 1344
SOAP 1345
Overloading WebMethods 1346
Caching Web Service Responses 1349
SOAP Headers 1350
Building a Web Service with SOAP Headers 1351
Consuming a Web Service Using SOAP Headers 1353
Requesting Web Services Using SOAP 1.2 1355
Consuming Web Services Asynchronously 1357
Windows Communication Foundation 1360
The Larger Move to SOA 1360
WCF Overview 1361
Building a WCF Service 1362
Building the WCF Consumer 1370
Adding a Service Reference 1370
Working with Data Contracts 1374
Namespaces 1379
Summary 1379
Chapter 30: Localization 1381
Cultures and Regions 1381
Understanding Culture Types 1382
The ASP.NET Threads 1383
Server-Side Culture Declarations 1386

Client-Side Culture Declarations 1387
Translating Values and Behaviors 1389
xxvi
Evjen ftoc.tex V2 - 01/28/2008 5:00pm Page xxvii
Contents
ASP.NET 3.5 Resource Files 1397
Making Use of Local Resources 1397
Making Use of Global Resources 1403
Looking at the Resource Editor 1406
Summary 1407
Chapter 31: Configuration 1409
Configuration Overview 1410
Server Configuration Files 1411
Application Configuration File 1413
How Configuration Settings Are Applied 1414
Detecting Configuration File Changes 1415
Configuration File Format 1415
Common Configuration Settings 1416
Connecting Strings 1416
Configuring Session State 1417
Compilation Configuration 1421
Browser Capabilities 1423
Custom Errors 1426
Authentication 1427
Anonymous Identity 1430
Authorization 1430
Locking-Down Configuration Settings 1433
ASP.NET Page Configuration 1433
Include Files 1435
Configuring ASP.NET Runtime Settings 1436

Configuring the ASP.NET Worker Process 1438
Storing Application-Specific Settings 1440
Programming Configuration Files 1441
Protecting Configuration Settings 1448
Editing Configuration Files 1452
Creating Custom Sections 1453
Using the NameValueFileSectionHandler Object 1454
Using the DictionarySectionHandler Object 1456
Using the SingleTagSectionHandler Object 1457
Using Your Own Custom Configuration Handler 1458
Summary 1460
Chapter 32: Instrumentation 1461
Working with the Event Log 1461
Reading from the Event Log 1462
Writing to the Event Logs 1464
xxvii
Evjen ftoc.tex V2 - 01/28/2008 5:00pm Page xxviii
Contents
Using Performance Counters 1468
Viewing Performance Counters Through an Administration Tool 1468
Building a Browser-Based Administrative Tool 1470
Application Tracing 1476
Understanding Health Monitoring 1477
The Health Monitoring Provider Model 1477
Health Monitoring Configuration 1479
Writing Events via Configuration: Running the Example 1486
Routing Events to SQL Server 1487
Buffering Web Events 1490
E-mailing Web Events 1492
Summary 1498

Chapter 33: Administration and Management 1499
The ASP.NET Web Site Administration Tool 1499
TheHomeTab 1501
The Security Tab 1501
The Application Tab 1510
The Provider Tab 1512
Configuring ASP.NET in IIS on Vista 1514
.NET Compilation 1517
.NET Globalization 1518
.NET Profile 1518
.NET Roles 1520
.NET Trust Levels 1520
.NET Users 1521
Application Settings 1522
Connection Strings 1523
Pages and Controls 1524
Providers 1524
Session State 1524
SMTP E-mail 1526
Summary 1527
Chapter 34: Packaging and Deploying ASP.NET Applications 1529
Deployment Pieces 1530
Steps to Take before Deploying 1530
Methods of Deploying Web Applications 1531
Using XCopy 1531
Using the VS Copy Web Site Option 1534
Deploying a Precompiled Web Application 1537
Building an Installer Program 1539
xxviii
Evjen ftoc.tex V2 - 01/28/2008 5:00pm Page xxix

Contents
Looking More Closely at Installer Options 1547
Working with the Deployment Project Properties 1550
The File System Editor 1554
The Registry Editor 1557
The File Types Editor 1559
The User Interface Editor 1561
The Custom Actions Editor 1562
The Launch Conditions Editor 1564
Summary 1565
Appendix A: Migrating Older ASP.NET Projects 1567
Migrating Is Not Difficult 1567
Running Multiple Versions of the Framework Side by Side 1568
Upgrading Your ASP.NET Applications 1568
When Mixing Versions — Forms Authentication 1570
Upgrading — ASP.NET Reserved Folders 1571
ASP.NET 3.5 Pages Come as XHTML 1571
No Hard-Coded .js Files in ASP.NET 3.5 1573
Converting ASP.NET 1.x Applications in Visual Studio 2008 1574
Migrating from ASP.NET 2.0 to 3.5 1580
Appendix B: ASP.NET Ultimate Tools 1583
Debugging Made Easier 1583
Firebug 1584
YSlow 1585
IE WebDeveloper Toolbar and Firefox WebDeveloper 1586
Aptana Studio — Javascript IDE 1588
Profilers: dotTrace or ANTS 1589
References 1590
PositionIsEverything.net, QuirksMode.org, and HTMLDog.com 1590
Visibone 1590

www.asp.net 1590
Tidying Up Your Code 1591
Refactor! for ASP.NET from Devexpress 1591
Code Style Enforcer 1592
Packer for .NET — Javascript Minimizer 1593
Visual Studio Add-ins 1594
ASPX Edit Helper Add-In for Visual Studio 1595
Power Toys Pack Installer 1596
Extending ASP.NET 1597
ASP.NET AJAX Control Toolkit 1597
xxix
Evjen ftoc.tex V2 - 01/28/2008 5:00pm Page xxx
Contents
Atif Aziz’s ELMAH — Error Logging Modules and Handlers 1598
Helicon’s ISAPI

Rewrite 1599
General Purpose Developer Tools 1600
Telerik’s Online Code Converter 1600
WinMerge and Differencing Tools 1601
Reflector 1602
CR

Documentor 1603
Process Explorer 1604
Summary 1605
Appendix C: Silverlight 1607
Extending ASP.NET Apps with Silverlight 1607
Step 1: A Basic ASP.NET Application 1609
Finding Vector-Based Content 1610

Converting Vector Content to XAML 1611
Tools for Viewing and Editing XAML 1614
Integrating with Your Existing ASP.NET Site 1620
Receiving Silverlight Events in JavaScript 1623
Accessing Silverlight Elements from JavaScript Events 1625
Summary 1626
Appendix D: ASP.NET Online Resources 1627
Author Blogs 1627
ASP.NET Influential Blogs 1627
Web Sites 1628
Index 1629
xxx
Evjen flast.tex V2 - 01/28/2008 5:02pm Page xxxi
Introduction
Simply put, you will find that ASP.NET 3.5 is an amazing technology to use to build your Web solutions!
When ASP.NET 1.0 was introduced in 2000, many considered it a revolutionary leap forward in the area
of Web application development. ASP.NET 2.0 was just as exciting and revolutionary and ASP.NET 3.5 is
continuing a forward march in providing the best framework today in building applications for the Web.
Although the foundation of ASP.NET was laid with the release of ASP.NET 1.0, ASP.NET 3.5 continues
to build on this foundation by focusing on the area of developer productivity.
This book covers the whole of ASP.NET. It not only introduces new topics, it also shows you examples
of these new technologies in action. So sit back, pull up that keyboard, and let’s have some fun!
A Little Bit of Histor y
Before organizations were even t hinking about developing applications for the Internet, much of the
application development focused on thick desktop applications. These thick-client applications were
used for everything from home computing and gaming to office productivity and more. No end was in
sight for the popularity of this application model.
During that time, Microsoft developers developed its thick-client applications using mainly Visual
Basic (VB).
Visual Basic was not only a programming language; it was tied to an IDE that allowed for easy thick-client

application development. In the Visual Basic model, developers could drop controls onto a form, set
properties for these controls, and provide code behind them to manipulate the events of the control. For
example, when an end user clicked a button on one of the Visual Basic forms, the code behind the form
handled the event.
Then, in the mid-1990s, the Internet arrived on the scene. Microsoft was unable to move the Visual Basic
model to the development of Internet-based applications. The Internet definitely had a lot of power,
and right away, the problems facing the thick-client application model were revealed. Internet-based
applications created a single instance of the application that everyone could access. Having one instance
of an application meant that when the application was upgraded or patched, the changes made to this
single instance were immediately available to each and every user visiting the application through a
browser.
To participate in the Web application world, Microsoft developed Active Server Pages (ASP). ASP was
a quick and easy way to develop Web pages. ASP pages consisted of a single page that contained a
mix of markup and languages. The power of ASP was that you could include VBScript or JScript code
instructions in the page e xecuted on t he Web server before the page was sent to the end user’s Web
browser. This was an easy way to create dynamic Web pages customized based on instructions dictated
by the developer.
ASP used script between brackets and percentage signs —
<
%%
> — to control server-side behaviors. A
developer could then build an ASP page b y starting with a set of static HTML. Any dynamic element
Evjen flast.tex V2 - 01/28/2008 5:02pm Page xxxii
Introduction
needed by the page was defined using a scripting language (such as VBScript or JScript). When a user
requested the page from the server by using a browser, the
asp.dll
(an ISAPI application that provided
a bridge between the scripting language and the Web server) would take hold of the page and define all
the dynamic aspects of the page on-the-fly based on the programming logic specified in the script. After

all the dynamic aspects of the page were defined, the result was an HTML page output to the browser of
the requesting client.
As the Web application model developed, more a nd more languages mixed in with the static HTML to
help manipulate the behavior and look of the output page. Over time, such a large number of languages,
scripts, and plain text could be placed in a typical ASP page that developers began to refer to pages
that utilized these features as spaghetti code. For example, it was quite possible to have a page that used
HTML, VBScript, JavaScript, Cascading Style Sheets, T-SQL, and more. In certain instances, it became a
manageability nightmare.
ASP evolved and new versions were released. ASP 2.0 and 3.0 were popular because the technology made
it relatively straightforward and easy to create Web pages. Their popularity was enhanced because they
appeared in the late 1990s, just as the dotcom era w as born. During this time, a mountain of new Web
pages and portals were developed, and ASP was one of the leading technologies individuals and com-
panies used to build them. Even today, you can still find a lot of
.asp
pages on the Internet — including
some of Microsoft’s own Web pages.
However, even at the time of the final release of Active Server Pages in late 1998, Microsoft employees Marc
Anders and Scott Guthrie had other ideas. Their ideas generated what they called XSP (an abbreviation
with no meaning) — a new way of creating Web applications in an object-oriented manner instead of the
procedural mannerof ASP 3.0. They showed their idea to many different groups within Microsoft, and they
were well received. In the summerof 2000, thebeta of what was then called ASP+ was released at Microsoft’s
Professional Developers Conference. The attendees eagerly started working with it. When t he technology
became available (with the final release of the .NET Framework 1.0), it was renamed ASP.NET —
receiving the .NET moniker that most o f Microsoft’s new products were receiving at that time.
Before the introduction of .NET, the model that classic ASP provided and what developed in Visual
Basic were so different that few VB developers also developed Web applications-and few Web applica-
tion developers also developed the thick-client applications of the VB world. There was a great divide.
ASP.NET bridged this gap. ASP.NET brought a Visual Basic–style eventing model to Web application
development, providing much-needed state management techniques over stateless HTTP. Its model is
much like the earlier Visual Basic model in that a developer can drag and drop a control onto a design

surface or form, manipulate the control’s properties, and even work with the code behind these controls
to act on certain events that occur during their lifecycles. What ASP.NET created is really the best of both
models, as you will see throughout this book.
I know you will enjoy working with this latest release of ASP.NET 3.5. Nothing is better than getting
your hands on a new technology and seeing what is possible. The following section discusses the goals
of ASP.NET so you can find out what to expect from this new offering!
The Goals of ASP.NET
ASP.NET 3.5 is another major release of the product and builds upon the core .NET Framework 2.0 with
additional classes and capabilities. This release of the Framework was code-named Orcas internally at
Microsoft. You might hear others referring to this release of ASP.NET as ASP.NET Orcas.ASP.NET3.5
continues on a path to make ASP.NET developers the most productive developers in the Web space.
xxxii
Evjen flast.tex V2 - 01/28/2008 5:02pm Page xxxiii
Introduction
Ever since the release of ASP.NET 2.0, the Microsoft team has had goals focused around developer
productivity, administration, and management, as well as performance and scalability.
Developer Productivity
Much of the focus of ASP.NET 3.5 is on productivity. Huge productivity gains were made with the
release of ASP.NET 1.x; could it be possible to expand further on those gains?
One goal the development team had for ASP.NET was to eliminate much of the tedious coding that
ASP.NET originally required and to make common ASP.NET tasks easier. The developer productivity
capabilities are presented throughout this book. Before venturing into these capabilities, this introduction
will first start by taking a look at the older ASP.NET 1.0 technology in order to make a comparison to
ASP.NET 3.5. Listing I-1 provides an example of using ASP.NET 1.0 to build a table in a Web page that
includes the capability to perform simple paging of the data provided.
Listing I-1: Showing data in a DataGrid server control with paging enabled (VB o nly)
<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs)
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Private Sub BindData()
Dim conn As SqlConnection = New SqlConnection("server=’localhost’;
trusted_connection=true; Database=’Northwind’")
Dim cmd As SqlCommand = New SqlCommand("Select * From Customers", conn)
conn.Open()
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds, "Customers")
DataGrid1.DataSource = ds
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
DataGrid1.CurrentPageIndex = e.NewPageIndex
BindData()
End Sub
</script>
<html>
xxxiii

×