Microsoft ASP And AJAX: Architecting Web Applications

2y ago
64 Views
6 Downloads
930.84 KB
63 Pages
Last View : 25d ago
Last Download : 2m ago
Upload by : Hayden Brunner
Transcription

Microsoft ASP.NET and AJAX:ArchitectingWeb ApplicationsDino Esposito

PUBLISHED BYMicrosoft PressA Division of Microsoft CorporationOne Microsoft WayRedmond, Washington 98052-6399Copyright 2009 by Dino EspositoAll rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any meanswithout the written permission of the publisher.Library of Congress Control Number: 2008940527Printed and bound in the United States of America.1 2 3 4 5 6 7 8 9 QWT 4 3 2 1 0 9Distributed in Canada by H.B. Fenn and Company Ltd.A CIP catalogue record for this book is available from the British Library.Microsoft Press books are available through booksellers and distributors worldwide. For further infor mation aboutinternational editions, contact your local Microsoft Corporation office or contact Microsoft Press International directly atfax (425) 936-7329. Visit our Web site at www.microsoft.com/mspress. Send comments to msinput@microsoft.com.Microsoft, Microsoft Press, ActiveX, Expression, IntelliSense, Internet Explorer, MS, MSDN, Natural, Silverlight,SQL Server, Visual Basic, Visual C#, Visual InterDev, Visual Studio, Windows, Windows Media, Windows Server andWindows Vista are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or othercountries. Other product and company names mentioned herein may be the trademarks of their respective owners.The example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depictedherein are fictitious. No association with any real company, organization, product, domain name, e-mail address, logo,person, place, or event is intended or should be inferred.This book expresses the author’s views and opinions. The information contained in this book is provided without anyexpress, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors willbe held liable for any damages caused or alleged to be caused either directly or indirectly by this book.Acquisitions Editor: Ben RyanDevelopmental Editor: Lynn FinnelProject Editor: Tracy BallEditorial Production: S4Carlisle Publishing ServicesTechnical Reviewer: Kenn Scribner; Technical Review services provided by Content Master, a member ofCM Group, Ltd.Cover: Tom Draper DesignBody Part No. X15-28134

To the people who help me to smile and often smile, play and laugh with me.—Dino

This page intentionally left blank

Contents at a GlancePart I123Part II45678The (Much Needed) Facelift for the Old WebUnder the Umbrella of AJAX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3The Easy Way to AJAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27AJAX Architectures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61Power to the ClientA Better and Richer JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . .JavaScript Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .AJAX Design Patterns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Client-Side Data Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Rich Internet Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .101129163223269Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309v

This page intentionally left blank

Table of ContentsAcknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xiIntroduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xiiiPart I1The (Much Needed) Facelift for the Old WebUnder the Umbrella of AJAX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3What Web Do We Want? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4It’s All About User Experience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Origins of the Web . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Paradox of the Web . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9The Biggest Benefit of AJAX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11What’s AJAX, Exactly? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12The Paradigm Shift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14AJAX and New Web Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17Adding AJAX Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17Architecture Is the Concern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18The Case for Rich Internet Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242 The Easy Way to AJAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27The ASP.NET AJAX Infrastructure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28The Page’s Script Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28The Microsoft JavaScript Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35Partial Rendering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37The UpdatePanel Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37Programming Updatable Panels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43Minimizing Data Transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47Shades of Partial Rendering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48AJAX and JavaScript Injections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53Remote Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54Widgets and Effects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60What do you think of this book? We want to hear from you!Microsoft is interested in hearing your feedback so we can continually improve our books and learningresources for you. To participate in a brief online survey, please visit:www.microsoft.com/learning/booksurvey/vii

viiiTable of Contents3AJAX Architectures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61The AJAX Service Layer Pattern. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62Architectural Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62Inside the HTTP Façade . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70The AJAX Presentation Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79Security Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83The AJAX Server Pages Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87Architectural Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88The Classic Postback Model Revisited . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90Libraries in Action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97Part II4Power to the ClientA Better and Richer JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . 101JavaScript Today . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102The Language and the Browser. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102Pillars of the Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105JavaScript (If Any) of the Future . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108The Microsoft AJAX Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110Overview of the Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110JavaScript Language Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112Object-Oriented Extensions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115Framework Facilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1265JavaScript Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129From Server Controls to JavaScript Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130The ASP.NET Factor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130The Widget Factor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132The jQuery Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137The Library at a Glance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138The Core Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140jQuery Selectors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142Working on Wrapped Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149jQuery Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161

Table of Contents6AJAX Design Patterns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163Design Patterns and Code Development. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163Generalities About Design Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164Patterns in AJAX Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166Patterns for JavaScript Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168The Singleton Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169The Model-View-Controller Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170The On-Demand JavaScript Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175The Predictive Fetch Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178Generalities of the Predictive Fetch Pattern . . . . . . . . . . . . . . . . . . . . . . . 178Creating a Reference Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180The Timeout Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186Generalities of the Timeout Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187A Timeout Pattern Reference Implementation. . . . . . . . . . . . . . . . . . . . . 188Related Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192The Progress Indicator Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194Generalities of the Progress Indicator Pattern . . . . . . . . . . . . . . . . . . . . . 194A Progress Indicator Reference Implementation . . . . . . . . . . . . . . . . . . . 196Canceling an Ongoing Remote Task. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206Other Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213The Micro-Link Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213The Cross-Domain Proxy Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215The Submission Throttling Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2217Client-Side Data Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223An Architectural Tour of ASP.NET Data Binding . . . . . . . . . . . . . . . . . . . . . . . . . 224Defining the HTML Template. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224Defining the Data Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230Data Binding at the Time of AJAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232The Browser-Side Template Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235Generalities of the BST Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235Creating a BST Reference Implementation . . . . . . . . . . . . . . . . . . . . . . . . 238The HTML Message Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250Generalities of the HM Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250Developing an HM Reference Implementation . . . . . . . . . . . . . . . . . . . . 253ix

xTable of ContentsA Look at ASP.NET AJAX 4.0. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260ASP.NET AJAX Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260ASP.NET Library for ADO.NET Data Services. . . . . . . . . . . . . . . . . . . . . . . 266Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2688Rich Internet Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269Looking for a Richer Web . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269The Dream of Binary Code Running over the Web . . . . . . . . . . . . . . . . . 270Browser Plug-ins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271Microsoft Silverlight at a Glance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274Elements of the Silverlight Architecture. . . . . . . . . . . . . . . . . . . . . . . . . . . 275Graphics and Multimedia . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277Building Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279The Programming Model of Microsoft Silverlight . . . . . . . . . . . . . . . . . . . . . . . 282WPF-Based User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282The .NET Base Class Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286Isolated Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289Networking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295Microsoft Silverlight and Code Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302The Security Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302Security Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303Secure by Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309What do you think of this book? We want to hear from you!Microsoft is interested in hearing your feedback so we can continually improve our books and learningresources for you. To participate in a brief online survey, please visit:www.microsoft.com/learning/booksurvey/

AcknowledgmentsA team of people helped me to assemble this book.Ben Ryan was sneakily convinced to support the project on a colorful Las Vegas night,during an ethnic dinner during which we watched waiters coming up from and going downto the wine cellar in transparent elevators.Lynn Finnel just didn’t want to let Dino walk alone in this key project after brilliantlycoordinating at least five book projects in the past.Kenn Scribner is now Dino’s official book alter ego. Kenn started working with Dino onbooks back in 1998 in the age of COM and the Active Template Library. How is it possiblethat a book with Dino’s name on the cover isn’t reviewed and inspired (and fixed) by Kenn’sunique and broad perspective on the world of software? The extent to which Kenn can behelpful is just beyond human imagination.Roger LeBlanc joined the team to make sure that all these geeks sitting together at thesame virtual desktop could still communicate using true English syntax and semantics.I owe you all the (non-rhetorically) monumental “Thank you” for being so kind, patient,and accurate.—Dinoxi

This page intentionally left blank

IntroductionThis book is the Web counterpart to another recently released book I co-authored withAndrea Saltarello: Microsoft .NET: Architecting Applications for the Enterprise (MicrosoftPress, 2008). I wrote it, in part, in response to the many architectural questions—both smallquestions and big ones—that I was asked repeatedly while teaching ASP.NET, AJAX, andSilverlight classes.Everybody in the industry is committed to AJAX. Everybody understands the impact of it.Everybody recognizes the enormous power that can be derived from its employment inreal-world solutions.Very few, though, know exactly how to make it happen. There are so many variations to AJAXand so many implementations that even after you have found one that suits your needs, youare left wondering whether that is the best possible option.The fact is that AJAX triggered a chain reaction in the world of the Web. AJAX represents achange of paradigm for Web applications. And, as the history of science proves, a paradigmshift has always had a deep impact, especially in scenarios that were previously stable andconsolidated.I estimate that it will take about five years to absorb the word AJAX (and all of its background)into the new definition of the Web. And the clock started ticking about four years ago. Thetime at which we say “the Web” without feeling the need to specify whether it contains AJAXor not . . . well, that time is getting closer and closer. But it is not that time yet.Tools and programming paradigms for AJAX, which were very blurry just a few years ago,are getting sharper every day. Whether we are talking about JavaScript libraries or suitesof server controls, I feel that pragmatic architectures can be identified. You find themthoroughly discussed in Chapter 3, “AJAX Architectures.”Architecting a Web application today is mostly about deciding whether to prefer the richnessof the solution over

or Microsoft Visual C# 2008 Express Edition, and Microsoft Visual Web Developer 2008 Express Edition. Microsoft SQL Server 2005 Express Edition, Service Pack 2 or Microsoft SQL Server 2005, Service Pack 3, or Microsoft SQL Server 2008. The Northwind database of Microsoft SQL Server 2000 is used to demonstrate data-access techniques.

Related Documents:

ASP powder metallurgy HSS HSSconventional metallurgy ASP 2004 ASP 2015 ASP 2023 ASP 2030 ASP 2052 ASP 2055 What is broaching? Broaching can be both internal or external. Internal broaches generally create complex shapes of holes in the centre of tools such as non-circular holes, internal splines, keyways and flat surfaces.

Detailed instructions on getting asp.net-identity set up or installed. ASP.NET Identity Basic information ASP.NET identity is a membership management system which allows a user to register and login into a web application. ASP.NET identity system can be used in entire ASP.NET framework, like ASP.NET MVC, Web Forms, Web Pages, Web API and SignalR.

Changes in Oracle Providers for ASP.NET in ODAC 12c Release 4 xiv Changes in Oracle Providers for ASP.NET Release 11.2.0.2 xiv Changes in Oracle Providers for ASP.NET Release 11.2.0.1.2 xv 1 Introduction to Oracle Providers for ASP.NET 1.4 Connecting to Oracle Database Cloud Service 1-1 1.1 Overview of Oracle Providers for ASP.NET 1-1 1.2 Oracle Providers for ASP.NET Assembly 1-4 1.3 System .

Introduction to AJAX Pat Morin COMP 2405. 2 Outline What is AJAX? - History - Uses - Pros and Cons An XML HTTP Transaction - Creating an XMLHTTPRequest . In an AJAX application, the JavaScript code then communicates with the server behind the scenes. 5 An AJAX Application (Cont'd)

ASP.NET Core ASP.NET Core is HTTP pipeline implementation sits on top of .NET Core uses the middleware concept (but at a higher abstraction level than OWIN) comes with its own server (Kestrel) adds DI to provide services ASP.NET Core MVC is Microsoft's application framework Host.NET Core ASP.NET Core

Architecting for Performance Design Architecting for Performance Storage Architecting for Performance Processor Architecting for Performance Memory . such as Microsoft Exchange, Microsoft SQL Server or an Oracle database. Term originated in 2011 when VMware increased the virtual hardware limits on virtual machines

Over the years, Microsoft has introduced new ASP.NET-based web frameworks to address web development trends. Some such web frameworks include ASP.NET MVC, ASP.NET Web Pages, and more recently ASP.NET Core. With each new framework, some have predicted the imminent decline of ASP.NET Web Forms and criticized it as an outdated, outmoded web framework.

The Alex Rider series is a fast-paced and action-packed set of books, ideal for lovers of spies and action. Teen readers will adore this unforgettable and enthralling series. Tomasz Hawryszczuk, age 9 This series of books is a must read for anyone over the age of 9 who likes spy stories, gadgets and danger. Best books ever! The Alex Rider series is an amazing set of books based on a 14 year .