ebook img

Real World ASP.NET Best Practices PDF

219 Pages·2003·4.888 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Real World ASP.NET Best Practices

Real World ASP.NET Best Practices FARHAN MUHAMMAD AND MATT MILNER ApressTM Real World ASP.NET Best Practices Copyright © 2003 by Farhan Muhammad and Matt Milner Originally published by Apress in 2003 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 978-1-59059-100-0 ISBN 978-1-4302-0769-6 (eBook) DOI 10.1007/978-1-4302-0769-6 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. Technical Reviewer: Scott Stabbert Editorial Directors: Dan Appleman, Gary Cornell, Simon Hayes, Martin Streicher, Karen Watterson, John Zukowski Assistant Publisher: Grace Wong Project Manager: Tracy Brown Collins Development Editor: Ami Knox Copy Editor: Kristen Imler Compositor and Proofreader: Kinetic Publishing Services, LLC Indexer: Lynn Armstrong Cover Designer: Kurt Krames Production Manager: Kari Brooks Manufacturing Manager: Tom Debolski 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. I would like to dedicate this book to my lovely wife, Luna, whose continuous support and encouragement made this book possible. I would also like to dedicate this book to my parents, who taught me to do my best in everything I start. -Farhan Muhammad I would like to dedicate this book to my wife, Kristen, for the patience she exhibits about the many hours spent in front of the computer and the unlimited amount of support she provides for all my endeavors. I would not be where I am without her. -Matt Milner Contents at a Glance About the Author ................................................... xi About the Technical Reviewer .................................... xii Introduction ...................................................... xiii Chapter 1 The Age of ASP. NET .................................. 1 Chapter 2 Cache, Session, and View State ................... 11 Chapter 3 Client-Side JavaScript: Oh, What Fun! ........... 51 Chapter 4 Handling Data Effectively ......................... 71 Chapter 5 Using ASP.NET to Manage Lists ................... 109 Chapter 6 User Controls and Server Controls ............... 137 Chapter 7 Remoting and Web Services ........................ 161 Chapter 8 Configuring ASP.NET Applications ................ 179 Index .............................................................. 203 v Contents About the Authors ................................................. xi About the Technical Reviewer .................................... xii Introduction ...................................................... xiii Chapter 1 The Age of ASP. NET .. ............................. 1 The Concept of Code Behind: Separating Fact from Fiction ......................................................1 Using Inheritance in Code Behind ....................................5 Event Wiring ........................................................8 Staying Away from the InitializeComponent Method ....................9 Summary ............................................................ .1 0 Chapter 2 Cache, Session, and View State ............. . 11 Be Mindful of the Cache I .........................................1 1 Cache Pros and Cons .............................................. . 11 Performance Testing with Data Caching .............................. 13 When Good Cache Goes Bad ....................................... . 19 It's Still Too Slow! ..................................................2 2 Refreshing Cached Data ............................................2 3 Extracting Data from a Database and Saving It into an XML File ........ .2 4 Expiring Cache ....................................................2 7 The CacheltemRemovedCallback Delegate ............................2 7 Understanding the CacheDependency Class ..........................2 9 Losing Cached Information When Restarting the Application ...........3 0 The Scalability Issue with Cached Objects .............................3 0 Thrbo-Charging with Output Caching ................................3 1 Deciding Whether to Maintain View State .......................3 6 View State: Behind the Scenes .......................................3 8 Understanding the Session Object .............................. .42 In-Process Session ................................................ .4 3 State Server .......................................................4 3 SQL Server Session .....................· . ......................... ·.43 Performance Testing the Session Object ..............................4 4 Summary ............................................................ .s o vii Contents Chapter 3 Client-Side JavaScript: Oh, What Fun! ..................................... 51 Capturing Events Raised by HTML Controls with JavaScript ................................................ .5 2 Server Control Attributes .......................................... .5 3 JavaScript in ASP.NET: A Problematic Solution ........................ .5 4 Dynamically Generating JavaScript Code ......................... .5 5 Using the RegisterArrayDeclaration Method .......................... .5 6 Using the RegisterClientScriptBlock Method ......................... .6 2 Using the RegisterStartupScript Method ............................. .6 5 Using the RegisterOnSubmitStatement Method ........................6 8 Removing JavaScript Code Programmatically ..................... .6 9 Summary ............................................................ .6 9 Chapter 4 Handling Data Effectively .................... 71 Handling Data by Using DataSet .................................. .71 An Inherent Problem with DataSet ................................... 71 Using the Raw DataSet to Create a Vendor Management System ......... 72 Handling Data by Using Business Objects: A Better Approach ............................................... 76 Methods of the Customers Class ..................................... 79 Adding Business Rules to the Customers Class ........................ . 80 Handling Data by Using Strongly Typed Collections ............ .8 7 Getting to Know the CollectionBase Class ............................ . 87 Making CustomerCollection Strongly JYped .......................... .9 0 Using a Strongly JYped Collection with ASP. NET Server Controls ........ .9 5 The Magic Is Still with the !List Interface ............................. .9 8 Adding a Search Mechanism to the Strongly JYped Collection .......... .9 8 Adding Row State Capability to the Strongly JYped Collection ......... . 1 00 Providing the Ability to Sort the Strongly JYped Collection ............. 10 4 Summary ........................................................... .1 07 Chapter 5 Using ASP. NET to Manage Lists .............. 109 Data Binding Performance Differences .......................... .1 09 Data Binding Performance of the Data Grid Control .................. .1 10 Data Binding Performance of the Data List Control .................. .1 13 Data Binding Performance of the Repeater Control .................. . 116 viii Contents Data Binding Techniques and Their Effects .................... .1 20 Using an Inline Format Expression for Data Binding .................. .1 20 Using an Event Handler for Data Binding ............................ 122 Using Member Methods for Data Binding ............................ 128 Using User Controls Effectively ..................................... 132 Summary ........................................................... .1 36 Chapter 6 User Controls and Server Controls ......... 137 Choosing a Control Type ..........................................1 37 Workingwith User Controls ........................................ 137 Benefits of Partial-Page Caching ................................... .1 38 Working with Server Controls ...................................... 141 User Controls vs. Server Controls ...................................1 42 Best Practices with User Controls ............................. .1 43 Exposing Data to Subclasses, Containers, and Siblings ................ .1 43 Using Events to Communicate Between Controls .....................1 46 Supporting Templates with User Controls ........................... .1 49 Dynamically Loading User Controls ................................ .1 52 Best Practices with Server Controls .......................... ..1 53 Raising and Handling Events in Server Controls ..................... .1 53 Design Time Experience with Server Controls ....................... .1 54 Additional Control Best Practices ..............................1 55 Using View State Sparingly but Effectively ........................... .1 55 Using Client-Side Script with Controls .............................. .1 56 Indicating the Script File Version ................................... 157 Summary ............................................................1 60 Chapter 1 Remoting and Web Services ................... 161 Remoting Overview .................................................1 62 Transport ........................................................ 162 Serialization Format .............................................. 162 Server Host ..................................................... .1 62 Activation ....................................................... 162 State Management ................................................ 163 Web Services Overview ............................................1 63 Tell Me Already! When Should I Use One or the Other? ................. 163 Best Practices That Are Common to Remoting and Web Services ...............................................1 64 Securing Your Remote Communication .............................. 165 Performance ..................................................... 166 ix Contents Remoting Best Practices ..........................................1 69 Managing Types and Interfaces ..................................... 170 Web Services Best Practices .................................... .1 74 ManagingWSDL on the Server and Service Locations on the Client ................................................. 174 Summary ........................................................... .1 77 Chapter 8 Configuring ASP. NET Applications .......... 179 Understanding the XML Configuration System ....................1 79 Identifying Configuration Sections and Handlers ............. .1 81 Leveraging the Built-In Configuration Handlers ...............1 85 User- or Environment-Specific Settings .........................1 86 Application Domains and Automatic Reloading of Configuration Settings .....................................1 90 Cascading Configuration ..........................................1 91 Creating Custom Configuration Section Handlers ...............1 97 Summary ............................................................2 01 Index ............................................................. 203 X About the Authors FARHAN MUHAMMAD is the Chief Architect at ILM Professional Services. He is a technology enthu siast and has been an evangelist for the .NET technology since its inception. He leads the 1\vin Cities .NET User Group, a 400-member-strong community that focuses on sharing .NET knowl edge among its members. He sits on the board of directors for the International .NET Association (INETA), where he is responsible for developing strategies for supporting .NET-focused communi ties in every corner of the world. He also leads INETA's Speakers Bureau, a very successful pro gram that connects user groups throughout the U.S. with top-notch .NET experts. Farhan hosts the Executive .NET seminar on a regular basis, where exec utives are educated on the short-and long-term impact of the .NET technology on their businesses. He has a masters degree in software engineering from the University of Minnesota. MATT MILNER is a consultant in Minneapolis, where he designs and develops .NET applications. He focuses on solving business problems by using Microsoft technologies and is enthusiastic about .NET's capabilities for building enterprise class applications. In addition to his work with clients, Matt enjoys helping others learn about .NET, which is why he has contributed to several other books and articles on .NET, and is an active partic ipant and presenter in the local .NET user group. xi

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.