270 likes | 528 Views
WEB322 ASP.NET Internals: Under the Covers – Exploring Internals, Page Lifecycle and the Compilation Model. Simon Calvert Program Manager Web Platform and Tools Team Microsoft Corporation. Agenda. ASP.NET compilation Development cycles and options: Dynamic compilation Pre-compilation
E N D
WEB322ASP.NET Internals: Under the Covers – Exploring Internals, Page Lifecycle and the Compilation Model Simon Calvert Program Manager Web Platform and Tools Team Microsoft Corporation
Agenda • ASP.NET compilation • Development cycles and options: • Dynamic compilation • Pre-compilation • Build extensibility • ASP.NET page lifecycle • Call backs, cross-page post • Asynchronous pages
Deploy Test/ Production ASPX … (CS/VB) App.DLL Deploy Test/Production ASPX … CS/VB App.DLL Layout (xcopy, copy web, build) ASPX … : Allows changes Code: Can remove. Changes rebuild App.DLL App.DLL: Pre-built or build Runtime: ASP.NET Dynamic compilation of known ‘file’ types Knows ‘single-file’ only ASP.NET v1.xDevelopment Cycles Design & Develop ASPX … CS/VB App.DLL Design-time: VS Pages: Code-behind Control: Code ‘spit’ Objects: \bin (own dll) Build: (App.DLL)
An (optional) class-name for the page-gen’ class File containing separated code. Designer only. Class that the page-gen’ inherits from Dynamic compile <%@ Page codebehind=“wf1.aspx.cs” inherits=“App1.WF1” classname=“MyClass” VS Build (pre-compile) Class defined in codebehind App1.WF.. ASP.MyClass2 Auto-generated page class Auto-generated page class ASP.MyClass Class defined in codebehind App1.WF1 System.Web.UI.Page namespace App1 { public class WF1 : System.Web.UI.Page { .. } } Code behind class. Namespace driven by project and folder (C#). Base class. Final base is System.Web.UI.Page ASP.NET v1.x CompilationPage Compilation
Deploy Test/ Production ASPX … DLL Deploy Test/ Production ASPX … WSDL, XSD, RESX CS/VB DLL Deploy Test/ Production DLL Layout: (xcopy, build ..) Dynamic compilation: Pre-compilation: W/o source and/or markup (allows changes) ASP.NET v2Development Cycles Design & Develop ASPX … WSDL, XSD, RESX CS/VB DLL Design-time: VS Pages: Code-behind or single file Control: No code ‘spit’ Runtime: ASP.NET Dynamic compilation of file ‘types’, (extensible) Compilation of specialized folders
Dynamic compile An (optional) class-name for the page-gen class File containing separated code Class that the page-gen inherits from <%@ Page codefile=“default.aspx.cs” inherits=“_Default” classname=“MyClass” public partial class _Default : System.Web.UI.Page Class is ‘partial’. Combined to auto-gen’ partial class Base Class. Final base is System.Web.UI.Page Auto-generated partial class Default2 Partial class defined in codefile Default2 MyClass2 Auto-generated page class MyClass Auto-generated page class _Default Auto-generated partial class _Default Partial class defined in codefile System.Web.UI.Page ASP.NET v2 CompilationPage Compilation
ASP.NET v2 CompilationSpecialized Folders \WeatherForecastApp \App_GlobalResources \App_WebReferences • Global Resources • Strongly-typed resources • Shared in application \App_Code • Web Service References • Folder structure defines type • Dynamic URL proxy generation • Consumable throughout application global.ASAX • Bus’ Logic, Base & Utility Classes .. • Compile assembly (or many in order in <codeSubDirectories>) • Single language per folder • Can contain ‘non-code’ types \App_Browsers • Extends HttpApplication • Application events default.aspx • Browser Capabilities • .BROWSER files • Compiled on demand • Page compilation • Compiled on demand • Batching and dependencies • Local resources compiled • Theme and master-pages compiled on demand \App_LocalResources \App_Themes\Theme
ASP.NET v2 Pre-compilationScenarios • No ‘penalty’ for first-time request: • In-place pre-compilation • Deploy to a server: • No ‘code’ or markup on the server • Allow markup for minor changes, UI layout • Ship to a third party, IP restriction: • Package deployed application
Pre-compile Auto-generated page class MyPage2 Auto-generated partial Default2 Partial class defined in codefile Default2 Auto-generated partial ‘stub’ HomePage HomePage Partial class defined in codefile System.Web.UI.Page MyPage Auto-generated page class ASP.NET v2 Pre-compilationPage Allows Updates <%@ Page codefile=“home.aspx.cs” inherits=“HomePage” classname=“MyPage” <%@ Page codefile=“home.aspx.cs” inherits=“HomePage” classname=“MyPage” public partial class HomePage : System.Web.UI.Page Dynamic compile <%@ Page inherits=“HomePage, App_Web_#####” classname=“MyPage”
ASP.NET v2 Build ExtensibilityScenarios • File-based type extensibility: • Create custom types from arbitrary file types, e.g. XSD in \App_Code • Create custom handlers, e.g. ASHX • Create custom content, e.g. ASCX • Non-file based source extensibility: • Move web content to a database
ASP.NET v2 Page Framework Page Lifecycle • Methods, events, auto-hookups (Page_): • OnPreInit: Dynamic MasterPageFile, Theme • OnPreLoad, OnLoadComplete .. • InitializeCulture: Dynamic Culture/UICulture code-gen call when attributes defined • Partial page lifecycle: • Cross-page posts, control call backs .. • Asynchronous page
Initialize Load Pre-render Save State Render Unload Load State Raise Callback Event:RaiseCallbackEvent ASP.NET v2 Page Framework Callback Lifecycle Control Developer Scenario C GET C-BK
ASP.NET v2 Page Framework Cross-page Post <%@ page title=“Posted From” %> <script runat=“server”> public String TextBoxText { get { return TB.Text; } } </script> .. <asp:textbox runat=‘server” id=“TB” /> <asp:button runat=“server” .. postbackurl=“~/To.aspx” /> .. =============================================================== <@% Page title=“Posted To” %> <%@ PreviousPageType virtualPath=“~/From.aspx” %> <script runat=“server”> protected void Page_Load(object sender, eventArgs e) { if (MyLabel.Text = PreviousPage.TextBoxText; } </script> <asp:label runat=‘server” id=“MyLabel” />
Initialize Load Pre-render Save State Render Unload Load State and Post Data Raise Changed Events and Postback Event ASP.NET v2 Page Framework Cross-page Post Lifecycle Page Developer Scenario PrevPage P GET
ASP.NET v2 Page FrameworkAsynchronous Page Model • 3-tier web applications: • Synchronous pages (v1.x, v2): • Remote resource (web service, database) is unresponsive threads are blocked • Web application may be unresponsive • Asynchronous pages (v2): • Create non-blocking call to access remote resources • Isolates issue to pages accessing remote resources • Potential to reduce # threads, improve latency and throughput
ASP.NET v2 Page FrameworkAsynchronous Page Model • V1.x: Pages make sync (blocking) Web Service calls • Can use IHttpAsyncHandler(not a page) • V2: New ‘event’ style async pattern • Simplifies making async calls • V2: Pages can be async: • ‘Event’ or BeginXXXX/EndXXXX styles
ASP.NET v2 Page FrameworkAsynchronous Page Model <%@ page async=“true” %> <script runat=“server”> private String wsResult; protected void Page_Load(Object s, EventArgs e) { WS ws = new WS(); ws.MethodCompleted += new MethodCompletedEventHandler(this.MyHandler); ws.MethodAsync(); } void MyHandler(Object s, MethodCompletedEventArgs e) { wsResult = e.Result; } .. </script>
Initialize Load Pre-render Save State Render Unload Load State and Post Data Raise Changed Events and Postback Event Async Point: Suspension of lifecycle OnPreRenderComplete ASP.NET v2 Page Framework Async Page Lifecycle Page Developer Scenario GET/ POST P
WEB320 ASP.NET Best Practices and Techniques for Migrating ASP.NET 1.x Applications to ASP.NET 2.0 WEB323/324 Overview of ASP.NET 2.0 (Part 1) and (Part2) WEBC11 Q&A ASYNC, Compilation and other 500+ Level Topics With the Web Platform Development Team http://www.asp.net Resources
Your Feedbackis Important! Please Fill Out a Survey forThis Session on CommNet
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.