Praise for Building a Web 2.0 Portal with ASP.NET 3.5 “Omar and his collaborators have applied their awesome talents and a huge amount of time to crafting what might be the most advanced web site yet that’s based on ASP.NET and Ajax. In this book, Omar distills everything he’s learned from his experience, going indepth into design goals, architecture, and implementation, including many pitfalls that he teaches you how to avoid. If you’re serious about creating a high-performance, modern, Ajax-based ASP.NET web site, Building a Web 2.0 Portal with ASP.NET 3.5 is for you.” — Mike Pope, Microsoft User Education, Microsoft Corporation
“An outstanding overview of the technologies, techniques, and best practices involved in working with today’s most popular web application model. Highly recommended for any web developer who wants to stay relevant.” — Craig Wills, Training Manager, Infusion
Building a Web 2.0 Portal with ASP.NET 3.5
Other Microsoft .NET resources from O’Reilly Related titles
.NET Books Resource Center
C# 3.0 Cookbook™ C# 3.0 Design Patterns C# 3.0 in a Nutshell Learning ASP.NET 2.0 with AJAX
Programming ASP.NET Programming ASP.NET AJAX Programming C# 3.0 Programming .NET 3.5
dotnet.oreilly.com is a complete catalog of O’Reilly’s books on .NET and related technologies, including sample chapters and code examples. ONDotnet.com provides independent coverage of fundamental, interoperable, and emerging Microsoft .NET programming and web services technologies.
Conferences
O’Reilly brings diverse innovators together to nurture the ideas that spark revolutionary industries. We specialize in documenting the latest tools and systems, translating the innovator’s knowledge into useful skills for those in the trenches. Visit conferences.oreilly.com for our upcoming events. Safari Bookshelf (safari.oreilly.com) is the premier online reference library for programmers and IT professionals. Conduct searches across more than 1,000 books. Subscribers can zero in on answers to time-critical questions in a matter of seconds. Read the books on your Bookshelf from cover to cover or simply flip to the page you need. Try it today for free.
Building a Web 2.0 Portal with ASP.NET 3.5
Omar AL Zabir
Beijing • Cambridge • Farnham • Köln • Paris • Sebastopol • Taipei • Tokyo
Building a Web 2.0 Portal with ASP.NET 3.5 by Omar AL Zabir Copyright © 2008 Omar AL Zabir. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (safari.oreilly.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or
[email protected].
Editor: John Osborn Production Editor: Laurel R.T. Ruma Copyeditor: Laurel R.T. Ruma Proofreader: Mary Brady
Indexer: John Bickelhaupt Cover Designer: Karen Montgomery Interior Designer: David Futato Illustrators: Robert Romano and Lesley Borash
Printing History: December 2007:
First Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Building a Web 2.0 Portal with ASP.NET 3.5, the image of a giant green sea anemone, and related trade dress are trademarks of O’Reilly Media, Inc. Microsoft, MSDN, the .NET logo, Visual Basic, Visual C++, Visual Studio, and Windows are registered trademarks of Microsoft Corporation. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.
This book uses RepKover™, a durable and flexible lay-flat binding. ISBN-10: 0-596-51050-0 ISBN-13: 978-0-596-51050-3 [C]
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi 1. Introducing Web Portals and Dropthings.com . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Defining a Web Portal Defining a Web 2.0 Portal Using a Web Portal Navigating Dropthings Using ASP.NET AJAX Using C# 3.0 and .NET 3.5 Summary
2 4 4 5 8 9 10
2. Architecting the Web Portal and Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Using a Widget Framework Adding Widgets Maximizing the First-Visit Experience Rendering a Second-Visit Experience Improving ASP.NET AJAX Performance Adding Authentication and Authorization Preventing Denial-of-Service Attacks Summary
20 26 28 30 31 36 38 40
3. Building the Web Layer Using ASP.NET AJAX . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Implementing the Start Page of a Web Portal Building a Custom Drag-and-Drop Extender for a Multicolumn Drop Zone Implementing WidgetContainer Building Widgets Page Switching: Simulating a Nonpostback Experience
41 60 74 81 92
vii
Using the Profile Object Inside a Web Service Implementing Authentication and Authorization Implementing Logout Summary
94 95 98 100
4. Building the Data and Business Layers Using .NET 3.5 . . . . . . . . . . . . . . . . . 101 Introducing LINQ to SQL Building the Data Access Layer Using LINQ to SQL Introducing Windows Workflow Foundation Building the Business Layer Using WF Implementing the DashboardFacade Summary
101 104 112 113 127 133
5. Building Client-Side Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 Delaying Server-Side Widget Loading Content Proxy Building a Client-Side RSS Widget Building a Client-Side Flickr Widget Summary
135 138 142 146 151
6. Optimizing ASP.NET AJAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 Combining Multiple Ajax Calls into One Call Timing and Ordering Ajax Calls to the Server Using HTTP GET Calls Instead of HTTP POST Working with the this Function Summary
152 154 165 166 168
7. Creating Asynchronous, Transactional, Cache-Friendly Web Services . . . . 169 Scalability Challenges with Web Services Asynchronous Web Methods Modifying the ASP.NET AJAX Framework to Handle Web Service Calls Developing Your Own Web Service Handler Making an Asynchronous and Cache-Friendly Proxy Scaling and Securing the Content Proxy Summary
viii |
Table of Contents
169 171 175 177 189 191 196
8. Improving Server-Side Performance and Scalability . . . . . . . . . . . . . . . . . . . 197 Instrumenting Your Code to Identify Performance Problems Optimizing the HTTP Pipeline Optimizing ASP.NET 2.0/3.5 Before Going Live Optimizing Queries in the ASP.NET Membership Tables Optimizing the ASP.NET 2.0/3.5 Profile Provider Before You Go Live ASP.NET Production Challenges Redirecting Traffic from an Old Web Site to a New One Summary
198 199 200 201 203 219 221 223
9. Improving Client-Side Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 Understanding Web Caching Content Delivery Networks Optimizing Internet Explorer JavaScript Performance Reducing the Web Service Call Payload Loading the UI on Demand Using Read-Ahead Caching for Ajax Calls Hiding HTML Inside