| About This Book | xvii |
| CHAPTER 1: Introduction to Web Programming | 1 |
| About This Chapter | 1 |
| Before You Begin | 1 |
| Lesson 1: Types of Applications | 2 |
| What Can You Create? | 2 |
| How Web Applications Work | 3 |
| What ASP.NET Provides | 5 |
| Advantages of ASP.NET | 6 |
| Lesson 2: Using ASP.NET | 7 |
| Parts of a Web Application | 7 |
| Web Form Components | 9 |
| The .NET Framework | 11 |
| Programming Languages | 14 |
| Lesson 3: Using Visual Studio .NET | 18 |
| The Start Page | 18 |
| Visual Studio .NET Windows | 21 |
| The Toolbox | 24 |
| Editing Web Documents | 25 |
| Editing Code-Behind Files | 26 |
| Editing Single-Source Web Forms | 30 |
| The Solution Explorer | 32 |
| Running a Project | 33 |
| Setting Breakpoints and Watching Variables | 34 |
| Executing Statements | 36 |
| Getting Help | 37 |
| Summary | 39 |
| Lab: Getting Started with Visual Studio .NET | 40 |
| Exercise 1: Customize the Visual Studio .NET Environment | 40 |
| Exercise 2: Set Up a Web Hosting Account | 42 |
| Exercise 3: Choose a Service Provider | 43 |
| Exercise 4: Explore the ASP.NET QuickStart Tutorials | 46 |
| Review | 49 |
| CHAPTER 2: Creating Web Forms Applications | 51 |
| About This Chapter | 51 |
| Before You Begin | 51 |
| Lesson 1: Creating an ASP.NET Web Application Project | 52 |
| Creating a New Web Application | 52 |
| Organizing Your Projects with IIS | 53 |
| Creating Virtual Folders to Organize Web Applications | 54 |
| Creating a Virtual Folder | 54 |
| Creating a Subweb | 56 |
| Creating a New Project in the Virtual Folder | 58 |
| Adding Controls and Writing Code | 58 |
| The Files in a Web Forms Project | 62 |
| The Files in a Web Application | 64 |
| Lesson 2: Responding to Events | 65 |
| Events in the Life Cycle of a Web Application | 65 |
| Preserving Data on a Web Form | 67 |
| Application and Session Events | 68 |
| Web Form Events | 70 |
| Server Control Events | 72 |
| Lesson 3: Where Does Processing Occur? | 74 |
| Application Boundaries and Start Pages | 74 |
| How IIS and ASP.NET Manage Processes | 76 |
| Determining When an Application Ends | 76 |
| Summary | 78 |
| Lab: Building a Simple Web Application | 79 |
| Exercise 1: Create the User Interface | 79 |
| Exercise 2: Create a Class Named FlashCardClass | 80 |
| Exercise 3: Store a FlashCardClass Object in Session State | 83 |
| Exercise 4: Use the FlashCardClass Object from Web Form Events | 84 |
| Review | 87 |
| CHAPTER 3: Working with Web Objects | 89 |
| About This Chapter | 89 |
| Before You Begin | 89 |
| Lesson 1: Namespace Fundamentals | 90 |
| Understanding Namespaces | 90 |
| References vs. Imports | 96 |
| Classes and Modules | 96 |
| Creating Classes/Modules and Providing Access | 98 |
| Inheritance: Who's Deriving? | 102 |
| Overriding, Overloading, and Shadowing Members | 103 |
| In the Abstract | 109 |
| Delegates and Events | 112 |
| Interface-to-Face | 119 |
| Lesson 2: Namespaces in a Web Application | 123 |
| Overview of Web Namespaces | 123 |
| Using the Application Object | 125 |
| Using the Page Object | 126 |
| Using the Request Object | 128 |
| Using the Response Object | 130 |
| Lesson 3: Maintaining State Information | 132 |
| Overview of Levels of State | 132 |
| Using Context.Handler | 133 |
| Using Query Strings | 135 |
| Using Cookies | 136 |
| Using ViewState | 137 |
| Using Application and Session States | 139 |
| Structuring Access to State Variables | 139 |
| Turning Off Session State | 142 |
| Summary | 143 |
| Lab: Using Objects and Saving Data | 144 |
| Exercise 1: Create the User Interface | 144 |
| Exercise 2: Create a Translator Class | 145 |
| Exercise 3: Store a Translator Object in Session State | 148 |
| Exercise 4: Use the TransClass Object from Web Form Events | 149 |
| Review | 151 |
| CHAPTER 4: Creating a User Interface | 153 |
| About This Chapter | 153 |
| Before You Begin | 153 |
| Lesson 1: Using Controls | 154 |
| Selecting a Layout | 154 |
| Choosing the Right Control | 157 |
| Working with Text | 158 |
| Working with Tables and Lists | 161 |
| Adding Items to a List or Table at Design Time | 161 |
| Adding Items to a List or Table at Run Time | 162 |
| Getting the Selected Item from a List | 164 |
| Using Simple Data Binding with Lists | 165 |
| Adding Items to DataGrid, DataList, and Repeater Controls | 167 |
| Performing Commands | 170 |
| Getting and Setting Values | 174 |
| Displaying Graphics and Advertisements | 176 |
| Grouping Controls | 178 |
| Getting Dates | 180 |
| Getting Files from the Client | 182 |
| Lesson 2: Validating Data | 186 |
| Using Validation | 186 |
| Combining Validations | 189 |
| Canceling Validation | 191 |
| Customizing Validation | 192 |
| Lesson 3: Navigating Between Forms | 195 |
| Ways to Navigate | 195 |
| Using Hyperlinks and Redirection | 196 |
| Using the Transfer Method | 196 |
| Using the Execute Method | 199 |
| Displaying a Page in a New Browser Window | 200 |
| Summary | 204 |
| Lab: Building a Web-Based Text Editor | 205 |
| Exercise 1: Create the Sign-On Form | 205 |
| Exercise 2: Create the NewAccount Form | 208 |
| Exercise 3: Create the File Manager Form | 212 |
| Exercise 4: Create the File Editor Form | 216 |
| Exercise 5: Create the Not Authorized Web Form | 221 |
| Review | 223 |
| CHAPTER 5: Storing and Retrieving Data with ADO.NET | 225 |
| About This Chapter | 225 |
| Before You Begin | 225 |
| Lesson 1: Accessing Data with ADO.NET | 226 |
| Understanding ADO.NET | 226 |
| Connecting to a Database | 228 |
| Creating a Data Set | 231 |
| Displaying a Data Set | 233 |
| Creating a Custom Data View | 235 |
| Changing Records in a Database | 237 |
| How ADO.NET Refers to Objects | 237 |
| Adding, Changing, and Deleting Rows | 239 |
| Updating the Database from the DataSet | 241 |
| Creating a Database Connection at Run Time | 244 |
| Updating a Run-Time Database Connection | 245 |
| Storing Multiple Tables and Caching Data Sets | 248 |
| Lesson 2: Using Data Sets on Web Forms | 252 |
| Displaying a Data Set in a DataGrid Control | 252 |
| Displaying a Data Set in a DataList Control | 255 |
| Displaying Data Items in Other List Controls | 259 |
| Selecting Specific Records | 261 |
| Executing Commands on a Database | 263 |
| Returning a Value from a Database | 264 |
| Changing Records Directly in a Database | 266 |
| Retrieving Records Directly from the Database | 267 |
| Executing Stored Procedures | 270 |
| Lesson 3: Processing Transactions | 273 |
| Understanding Transactions | 273 |
| Data Set Transactions | 275 |
| Database Transactions | 278 |
| Enterprise Transactions | 282 |
| Summary | 283 |
| Lab: Building the Contact Management Application | 284 |
| Exercise 1: Start a Project and Create the SwitchBoard Form | 284 |
| Exercise 2: Add Database Components | 285 |
| Exercise 3: Create the AddContact Form | 288 |
| Exercise 4: Create the Calls Form | 294 |
| Exercise 5: Create the DeleteContact and ContactTypes Forms | 302 |
| Review | 304 |
| CHAPTER 6: Catching and Correcting Errors | 305 |
| About This Chapter | 305 |
| Before You Begin | 305 |
| Lesson 1: Using Exception Handling | 306 |
| Exception-Handling Techniques | 306 |
| Using Exception-Handling Structures | 308 |
| Causing Exceptions | 313 |
| Defining New Exceptions | 314 |
| Using Error Events | 315 |
| Lesson 2: Using Error Pages | 318 |
| Handling Internet-Related Exceptions | 318 |
| Using Application-Wide Error Pages | 320 |
| Using Page-Level Error Pages | 322 |
| Lesson 3: Logging Exceptions | 324 |
| Using Tracing to Log Errors | 324 |
| Turning Tracing On and Off | 325 |
| Writing Messages to the Trace Log | 326 |
| Reading the Trace Log | 328 |
| Summary | 330 |
| Lab: Adding Exception Handling to an Application | 331 |
| Exercise 1: Extend Exception Handling | 331 |
| Exercise 2: Add an Error Event Procedure | 334 |
| Exercise 3: Create and View the Trace Log | 336 |
| Exercise 4: Extend Exception Handling to Other Web Forms | 337 |
| Review | 338 |
| CHAPTER 7: Advanced Web Forms Programming | 339 |
| About This Chapter | 339 |
| Before You Begin | 339 |
| Lesson 1: Saving and Retrieving User Information | 340 |
| Identifying Web Application Users | 340 |
| Storing User Information on the Client | 341 |
| Facts About Cookies | 343 |
| Using Keys Within Cookies | 343 |
| Storing User Information on the Server | 345 |
| Creating Unique Keys to Identify Users | 345 |
| Creating a File to Store User Information | 346 |
| Creating an XML File | 347 |
| Creating an XML Schema | 347 |
| Specifying a Key Field | 348 |
| Reading the XML into a Data Set | 349 |
| Saving User Information on the Server | 350 |
| Retrieving User Information from the Data Set | 351 |
| Lesson 2: Using Unmanaged Code | 353 |
| Using Platform Invoke | 353 |
| Converting Data Types | 356 |
| Handling Exceptions from Unmanaged Procedures | 359 |
| Limitations of Unmanaged Code | 361 |
| Lesson 3: Interoperating with COM | 362 |
| Using COM Objects from .NET | 362 |
| Building .NET Objects for Use from COM | 365 |
| Hiding Public .NET Classes from COM | 366 |
| Tools Used by COM Interop | 372 |
| Handling Exceptions Between .NET and COM | 372 |
| Limitations of COM Interop | 372 |
| Lesson 4: Using Client-Side Scripts | 374 |
| Before You Use Scripts | 374 |
| Choosing a Scripting Language | 376 |
| Understanding the DOM | 376 |
| Adding Inline Scripts | 377 |
| Responding to Events with Script Procedures | 380 |
| Sending Mail | 386 |
| Lesson 5: Consuming XML Web Services | 389 |
| Finding XML Web Services | 389 |
| Using an XML Web Service | 390 |
| Using XML Web Services from Client-Side Scripts | 392 |
| Using Licensed XML Web Services | 394 |
| Summary | 397 |
| Lab: Using Advanced Features | 398 |
| Exercise 1: Check Advanced Feature Support | 399 |
| Exercise 2: Store User Information | 401 |
| Exercise 3: Create a Mail Web Form | 404 |
| Exercise 4: Create a Frame-Based User Interface | 407 |
| Exercise 5: Extra Practice Using Advanced Features | 409 |
| Review | 411 |
| CHAPTER 8: Maintaining Security | 413 |
| About This Chapter | 413 |
| Before You Begin | 413 |
| Lesson 1: Authenticating and Authorizing Users | 415 |
| Access by Anonymous Users | 415 |
| Access by Authenticated Users | 418 |
| Using Authentication with HTM and HTML Files | 420 |
| Lesson 2: Using Windows Authentication | 422 |
| Enabling Windows Authentication | 422 |
| Allowing or Denying Access to Specific Users | 426 |
| Using Role-Based Authorization | 426 |
| Getting the User Identity | 427 |
| Using IIS Settings with Windows Authentication | 428 |
| Using Impersonation | 430 |
| Lesson 3: Using Forms Authentication | 432 |
| Enabling Forms Authentication | 432 |
| Setting the Forms Authentication Mode | 433 |
| Creating a LogIn Web Form | 435 |
| Authenticating Users with a Database | 437 |
| Adding Users to a Database | 438 |
| Authenticating Users from a Database | 440 |
| Controlling Access to Specific Locations | 443 |
| Lesson 4: Using Passport Authentication | 445 |
| Enabling Passport Authentication | 445 |
| Lesson 5: Providing Secure Communication | 451 |
| Enabling Secure Communication | 451 |
| Generating a Certificate Request | 453 |
| Requesting a Certificate | 454 |
| Installing the Certificate | 455 |
| Using Secure Communications | 456 |
| Summary | 460 |
| Lab: Creating a Secure Application | 461 |
| Exercise 1: Enable Forms Authentication | 462 |
| Exercise 2: Create the LogIn Web Form | 462 |
| Exercise 3: Display User Information | 469 |
| Exercise 4: Advanced Topics | 471 |
| Review | 472 |
| CHAPTER 9: Building and Deploying Web Applications | 473 |
| About This Chapter | 473 |
| Before You Begin | 473 |
| Lesson 1: Building a Web Application | 474 |
| Setting Build Options | 474 |
| Identifying the Application | 478 |
| Configuring the Application | 480 |
| Lesson 2: Deploying a Web Application | 482 |
| Using the Upload Tools | 482 |
| Hosting on Your Own Server | 483 |
| Setting Up a Virtual Folder | 484 |
| Copying the Application | 484 |
| Installing Shared Components | 485 |
| Assigning Security Privileges | 486 |
| Lesson 3: Creating an Installation Program | 490 |
| Creating a Setup and Deployment Project | 490 |
| Modifying the Setup Project for Web Deployment | 494 |
| Reviewing the Setup Project's Contents and Adding Files | 495 |
| Renaming and Adding Virtual Folders | 496 |
| Adding Shared Components | 497 |
| Lesson 4: Maintaining a Deployed Application | 498 |
| Monitoring the Server | 498 |
| Viewing Events | 499 |
| Defining New Events | 500 |
| Creating Event Logs | 505 |
| Viewing Event Logs | 508 |
| Repairing Deployed Applications | 511 |
| Tuning Deployed Applications | 513 |
| Adjusting processModel Attributes | 513 |
| Adjusting sessionState Attributes | 514 |
| Optimization Tips | 515 |
| Lesson 5: Deploying Across Multiple Servers | 516 |
| Scaling Up with Multiple Processors | 516 |
| Scaling Up with Multiple Servers | 517 |
| Sharing State Information | 518 |
| Sharing Application State | 518 |
| Sharing Session State | 518 |
| Summary | 520 |
| Lab: Building and Deploying a Web Application | 521 |
| Exercise 1: Prepare the Application | 521 |
| Exercise 2: Deploy the Application | 521 |
| Exercise 3: Chart Application Performance | 522 |
| Review | 524 |
| CHAPTER 10: Testing Web Applications | 525 |
| About This Chapter | 525 |
| Before You Begin | 525 |
| Lesson 1: Creating Tests | 526 |
| Developing a Test Plan | 526 |
| Types of Tests | 527 |
| Unit Testing | 528 |
| Integration Testing | 531 |
| Regression Testing | 534 |
| Load Testing | 534 |
| Recording a Load Test | 534 |
| Setting Test Properties | 537 |
| Running Load Tests | 538 |
| Platform Testing | 539 |
| Lesson 2: Running Tests | 540 |
| Running Tests with ACT | 540 |
| Logging Test Results | 540 |
| Using Multiple Connections | 542 |
| Adding Users and Passwords | 543 |
| Adding Performance Counters | 545 |
| Mimicking Browser Types | 546 |
| Getting Content of Responses | 546 |
| Running Tests with .NET Assemblies | 547 |
| Registering .NET Assemblies | 548 |
| Locating the .NET Assembly | 549 |
| Creating the .NET Object | 549 |
| Running Unattended Builds and Tests | 551 |
| Creating a Command File | 552 |
| Scheduling Tasks | 553 |
| Viewing Log Files | 555 |
| Lesson 3: Debugging | 556 |
| Putting Test Results to Work | 556 |
| Using the Debug and Trace Classes | 560 |
| Displaying Alerts and Messages | 560 |
| Logging Debug and Trace Messages | 561 |
| Remote Debugging | 562 |
| Installing Remote Components | 562 |
| Setting Server Permissions | 563 |
| Attaching to a Remote Process | 564 |
| Summary | 567 |
| Lab: Testing and Debugging | 568 |
| Exercise 1: Review a Test Plan | 568 |
| Exercise 2: Write Unit Tests | 568 |
| Exercise 3: Create a Load Test | 569 |
| Exercise 4: Step Through a Remote Process | 569 |
| Review | 571 |
| CHAPTER 11: Creating Custom Web Controls | 573 |
| About This Chapter | 573 |
| Before You Begin | 574 |
| Lesson 1: Creating Web User Controls | 575 |
| Creating and Using User Controls | 575 |
| Creating a User Control and Drawing Its Interface | 576 |
| Writing the Control's Properties, Methods, and Events | 577 |
| Adding the Control to a Web Form | 580 |
| Using the Control in Code | 581 |
| Adding Events to the User Control | 582 |
| Enabling Grid Layout | 584 |
| Lesson 2: Creating Composite Custom Controls | 586 |
| Creating and Using Composite Custom Controls | 586 |
| Creating the Custom Control Project | 587 |
| Creating the Test Project | 590 |
| Adding the Custom Control to the Test Project | 592 |
| Creating the Composite Control's Appearance | 596 |
| Creating Properties and Methods | 599 |
| Handling Events | 603 |
| Raising Events | 604 |
| Handling Control Resizing | 606 |
| Superclassing Server Controls | 606 |
| Lesson 3: Creating Rendered Custom Controls | 609 |
| Creating and Using Rendered Controls | 609 |
| Creating the Rendered Control's Appearance | 610 |
| Storing Property Settings | 613 |
| Getting Contained Text | 614 |
| Responding to User Actions | 617 |
| Raising Cached Events | 617 |
| Raising Postback Events | 619 |
| Getting Data from the User | 622 |
| Adding Custom Controls to the Toolbox | 625 |
| Setting the Toolbox Icon and TagPrefix for Custom Controls | 627 |
| Summary | 629 |
| Lab: Creating Custom Controls | 630 |
| Exercise 1: Create an AddressBox User Control | 630 |
| Exercise 2: Create the DigitPad Composite Custom Control | 631 |
| Exercise 3: Create the BarChart Rendered Custom Control | 632 |
| Review | 633 |
| CHAPTER 12: Optimizing Web Applications with Caching | 635 |
| About This Chapter | 635 |
| Before You Begin | 635 |
| Lesson 1: Caching Web Forms | 636 |
| Using the OutputCache Directive | 636 |
| Caching Multiple Responses from a Single Web Form | 637 |
| Controlling Caching in Code | 639 |
| Controlling Where Items Are Cached | 641 |
| Lesson 2: Caching Parts of Web Forms | 642 |
| Caching Parts of a Web Form with User Controls | 642 |
| Caching Multiple Versions of a User Control | 643 |
| Using Cached User Controls in Code | 644 |
| Combining Web Form Caching and User Control Caching | 645 |
| Lesson 3: Caching Application Data | 646 |
| Using the Cache Object | 646 |
| Controlling How Long Data Is Cached | 649 |
| Responding to Cache Events | 649 |
| Updating the Cache When Data Changes | 651 |
| Lesson 4: Monitoring Cache Performance | 654 |
| Using the Performance Monitor | 654 |
| Choosing Cache Performance Counters | 655 |
| Summary | 657 |
| Lab: Combining Caching at Multiple Levels | 658 |
| Exercise 1: Cache Multiple Versions of the Web Form | 658 |
| Exercise 2: Cache a Customer List | 660 |
| Exercise 3: Cache Data from a Stored Procedure | 662 |
| Exercise 4: Test Cache Performance | 665 |
| Review | 667 |
| CHAPTER 13: Formatting Web Application Output | 669 |
| About This Chapter | 669 |
| Before You Begin | 669 |
| Lesson 1: Using Cascading Style Sheets | 670 |
| How Styles Work | 670 |
| Using Style Sheets with Web Forms | 672 |
| Modifying Styles | 673 |
| Adding Styles | 674 |
| Using Style Classes | 675 |
| Creating Styles for Specific Elements | 676 |
| Creating Nested Styles | 677 |
| Changing Style Sheets at Run Time | 679 |
| Using Behaviors | 681 |
| Lesson 2: Using XSL Transformations | 685 |
| How XSL Transformations Work | 685 |
| Creating an XML File | 687 |
| Creating an XSL File | 688 |
| Changing Layout | 690 |
| Including Other Templates | 692 |
| Repeating Tasks | 693 |
| Inserting Hyperlinks and Other HTML Elements | 695 |
| Sorting Items | 697 |
| Performing Conditional Tasks | 697 |
| Summary | 700 |
| Lab: Creating the Cookbook | 701 |
| Exercise 1: Create and Attach a Style Sheet | 701 |
| Exercise 2: Provide Alternative Style Sheets | 702 |
| Exercise 3: Perform XSL Transformation | 704 |
| Exercise 4: On Your Own | 705 |
| Review | 706 |
| CHAPTER 14: Providing Help | 707 |
| About This Chapter | 707 |
| Before You Begin | 707 |
| Lesson 1: Adding Help to Web Applications | 708 |
| Displaying ToolTips | 708 |
| Displaying Help as Web Forms or HTML | 709 |
| Displaying HTML Help | 711 |
| Lesson 2: Using the HTML Help Workshop | 714 |
| Creating HTML Help | 714 |
| Setting Project Options | 716 |
| Building Tables of Contents | 718 |
| Adding Index Entries | 722 |
| Adding Cross-References | 723 |
| Adding Related Topics | 724 |
| Creating Associative Links | 724 |
| Enabling Searches | 726 |
| Compiling and Previewing Help | 727 |
| Lesson 3: Linking HTML Help to Web Forms | 728 |
| Displaying the HTML Help Viewer | 728 |
| Displaying HTML Help in the Browser | 730 |
| Displaying Context-Sensitive Help | 730 |
| Summary | 733 |
| Lab: Building and Using an HTML Help File | 734 |
| Exercise 1: Create a Help Project | 734 |
| Exercise 2: Enable Contents, Index, and Search | 735 |
| Exercise 3: Add Index Keywords | 737 |
| Exercise 4: Link Help to a Web Form | 738 |
| Review | 740 |
| CHAPTER 15: Globalizing Web Applications | 741 |
| About This Chapter | 741 |
| Before You Begin | 741 |
| Lesson 1: Choosing an Approach | 742 |
| Ways to Globalize Web Applications | 742 |
| Detecting the User's Culture | 743 |
| Redirecting to Culture-Specific Web Applications | 744 |
| Redirecting Based on Primary Language | 745 |
| Setting Culture in Web.config | 747 |
| Adjusting to Current Culture at Run Time | 749 |
| Setting the Current Culture | 750 |
| Responding to the Thread's Culture | 753 |
| Using Satellite Assemblies | 754 |
| Lesson 2: Creating and Using Satellite Assemblies | 755 |
| How Satellite Assemblies Work | 755 |
| Enabling HTML Elements for Resources | 757 |
| Creating Resource Files | 758 |
| Loading Resource Files | 760 |
| Getting and Setting User-Interface Culture | 761 |
| Displaying Resource Strings | 762 |
| Lesson 3: Globalization Issues | 765 |
| General Programming Issues | 765 |
| Sorting and Comparing Strings | 765 |
| Custom Validation Controls | 765 |
| Building Strings | 766 |
| Getting Substrings | 766 |
| Character Encoding | 766 |
| Saving Encoded Files | 766 |
| Using Other Encodings | 767 |
| Summary | 769 |
| Lab: Creating a Currency Converter | 770 |
| Exercise 1: Create the Currency Converter Web Form | 770 |
| Exercise 2: Create the User-Interface Resource Files | 771 |
| Exercise 3: Load Resources Based on User Culture | 773 |
| Exercise 4: Perform Culture-Dependent Conversion | 775 |
| Review | 778 |
| APPENDIX A Questions and Answers | 779 |
| GLOSSARY | 793 |
| INDEX | 799 |