<<

www.allitebooks.com 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 . In this book, Omar distills everything he’s learned from his experience, going in- depth 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 model. Highly recommended for any web developer who wants to stay relevant.” — Craig Wills, Training Manager, Infusion

www.allitebooks.com www.allitebooks.com BuildingaWeb2.0Portal with ASP.NET3.5

www.allitebooks.com Other Microsoft .NET resources from O’Reilly

Related titles C# 3.0 Cookbook™ Programming ASP.NET C# 3.0 Design Patterns Programming ASP.NET AJAX C# 3.0 in a Nutshell Programming C# 3.0 Learning ASP.NET 2.0 with Programming .NET 3.5 AJAX

.NET Books dotnet.oreilly.com is a complete catalog of O’Reilly’s books on Resource Center .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 docu- menting 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 (.oreilly.com) is the premier online refer- ence 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 sim- ply flip to the page you need. Try it today for free.

www.allitebooks.com Building a Web 2.0 Portal with ASP.NET 3.5

Omar AL Zabir

Beijing • Cambridge • Farnham • Köln • Paris • Sebastopol • Taipei • Tokyo

www.allitebooks.com 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 Indexer: John Bickelhaupt Production Editor: Laurel R.T. Ruma Cover Designer: Karen Montgomery Copyeditor: Laurel R.T. Ruma Interior Designer: David Futato Proofreader: Mary Brady 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]

www.allitebooks.com Table of Contents

Preface ...... xi 1. Introducing Web Portals and Dropthings.com ...... 1 Defining a Web Portal 2 Defining a Web 2.0 Portal 4 Using a Web Portal 4 Navigating Dropthings 5 Using ASP.NET AJAX 8 Using C# 3.0 and .NET 3.5 9 Summary 10

2. Architecting the Web Portal and Widgets ...... 12 Using a Widget Framework 20 Adding Widgets 26 Maximizing the First-Visit Experience 28 Rendering a Second-Visit Experience 30 Improving ASP.NET AJAX Performance 31 Adding Authentication and Authorization 36 Preventing Denial-of-Service Attacks 38 Summary 40

3. Building the Web Layer Using ASP.NET AJAX ...... 41 Implementing the Start Page of a Web Portal 41 Building a Custom Drag-and-Drop Extender for a Multicolumn Drop Zone 60 Implementing WidgetContainer 74 Building Widgets 81 Page Switching: Simulating a Nonpostback Experience 92

vii

www.allitebooks.com Using the Profile Object Inside a Web Service 94 Implementing Authentication and Authorization 95 Implementing Logout 98 Summary 100

4. Building the Data and Business Layers Using .NET 3.5 ...... 101 Introducing LINQ to SQL 101 Building the Data Access Layer Using LINQ to SQL 104 Introducing Windows Workflow Foundation 112 Building the Business Layer Using WF 113 Implementing the DashboardFacade 127 Summary 133

5. Building -Side Widgets ...... 134 Delaying Server-Side Widget Loading 135 Content Proxy 138 Building a Client-Side RSS Widget 142 Building a Client-Side Widget 146 Summary 151

6. Optimizing ASP.NET AJAX ...... 152 Combining Multiple Ajax Calls into One Call 152 Timing and Ordering Ajax Calls to the Server 154 Using HTTP GET Calls Instead of HTTP POST 165 Working with the this Function 166 Summary 168

7. Creating Asynchronous, Transactional, Cache-Friendly Web Services . . . . 169 Scalability Challenges with Web Services 169 Asynchronous Web Methods 171 Modifying the ASP.NET AJAX Framework to Handle Web Service Calls 175 Developing Your Own Web Service Handler 177 Making an Asynchronous and Cache-Friendly Proxy 189 Scaling and Securing the Content Proxy 191 Summary 196

viii | Table of Contents

www.allitebooks.com 8. Improving Server-Side Performance and Scalability ...... 197 Instrumenting Your Code to Identify Performance Problems 198 Optimizing the HTTP Pipeline 199 Optimizing ASP.NET 2.0/3.5 Before Going Live 200 Optimizing Queries in the ASP.NET Membership Tables 201 Optimizing the ASP.NET 2.0/3.5 Profile Provider Before You Go Live 203 ASP.NET Production Challenges 219 Redirecting Traffic from an Old Web Site to a New One 221 Summary 223

9. Improving Client-Side Performance ...... 224 Understanding Web Caching 224 Content Delivery Networks 234 Optimizing JavaScript Performance 238 Reducing the Web Service Call Payload 246 Loading the UI on Demand 247 Using Read-Ahead Caching for Ajax Calls 250 Hiding HTML Inside

Example 9-23 shows how the HTML is extracted from the