Download presentation
Presentation is loading. Please wait.
Published byDwight Tucker Modified over 9 years ago
1
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
3
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
4
ASP.NET V2 Web Application
5
Design-time: VS Pages: Code-behind Control: Code ‘spit’ Objects: \bin (own dll) Build: (App.DLL) ASP.NET v1.x Development Cycles Design & Develop ASPX … CS/VBApp.DLL Deploy Test/Production ASPX … CS/VBApp.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
6
System.Web.UI.Page ASP.NET v1.x Compilation Page Compilation Class defined in codebehind App1.WF.. Class defined in codebehind App1.WF1 VS Build (pre-compile) Auto- generated page class ASP.MyClass2 Auto- generated page class ASP.MyClass Dynamic compile <%@ Page codebehind=“wf1.aspx.cs” inherits=“App1.WF1” classname=“MyClass” File containing separated code. Designer only. Class that the page-gen’ inherits from An (optional) class-name for the page-gen’ class namespace App1 { public class WF1 : System.Web.UI.Page {.. } } Base class. Final base is System.Web.UI.Page Code behind class. Namespace driven by project and folder (C#).
7
Layout: (xcopy, build..) Dynamic compilation: Pre-compilation: W/o source and/or markup (allows changes) Deploy Test/ Production ASPX … WSDL, XSD, RESX CS/VBDLL Deploy Test/ Production ASPX … DLL Deploy Test/ ProductionDLL Design-time: VS Pages: Code-behind or single file Control: No code ‘spit’ ASP.NET v2 Development Cycles Design & Develop ASPX … WSDL, XSD, RESX CS/VBDLL Runtime: ASP.NET Dynamic compilation of file ‘types’, (extensible) Compilation of specialized folders
8
Auto- generated partial class Default2 Partial class defined in codefile Default2 Auto- generated page class MyClass2 Auto- generated page class MyClass Auto- generated partial class _Default Partial class defined in codefile _DefaultSystem.Web.UI.Page Dynamic compile ASP.NET v2 Compilation Page Compilation <%@ Page codefile=“default.aspx.cs” inherits=“_Default” classname=“MyClass ” File containing separated code Class that the page-gen inherits from An (optional) class-name for the page-gen class 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
9
ASP.NET v2 Code-Behind and Compilation
10
ASP.NET v2 Compilation Specialized Folders \WeatherForecastApp \App_Code \App_Code global.ASAX global.ASAX Extends HttpApplication 1.Application events Bus’ Logic, Base & Utility Classes.. Compile assembly (or many in order in ) 1.Single language per folder 2.Can contain ‘non-code’ types \App_GlobalResources \App_GlobalResources Global Resources 1.Strongly-typed resources 2.Shared in application \App_WebReferences \App_WebReferences Web Service References 1.Folder structure defines type 2.Dynamic URL proxy generation 3.Consumable throughout application \App_Browsers \App_Browsers Browser Capabilities 1..BROWSER files 2.Compiled on demand default.aspx default.aspx \App_LocalResources \App_LocalResources \App_Themes\Theme \App_Themes\Theme Page compilation 1.Compiled on demand 2.Batching and dependencies 3.Local resources compiled 4.Theme and master-pages compiled on demand
11
ASP.NET v2 Pre-compilation Scenarios 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
12
Pre-compilation
13
Auto- generated partial Default2 Partial class defined in codefile Default2 Auto- generated partial ‘stub’ HomePage Partial class defined in codefile HomePageSystem.Web.UI.Page <%@ Page codefile=“home.aspx.cs” inherits=“HomePage” classname=“MyPage” public partial class HomePage : System.Web.UI.Page Pre-compile Auto- generated page class MyPage2 Auto- generated page class MyPage ASP.NET v2 Pre-compilation Page Allows Updates <%@ Page inherits=“HomePage, App_Web_#####” classname=“MyPage” Dynamic compile <%@ Page codefile=“home.aspx.cs” inherits=“HomePage” classname=“MyPage”
14
ASP.NET v2 Build Extensibility Scenarios 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
15
Custom BuildProvider and VirtualPathProvider
16
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
17
ASP.NET v2 Page Framework Callback Lifecycle C Control Developer Scenario GET C-BK Initialize Load State Load Pre-render Save State Render Unload Raise Callback Event: RaiseCallbackEvent
18
ASP.NET v2 Page Framework Cross-page Post public String TextBoxText { get { return TB.Text; } }.... =============================================================== protected void Page_Load(object sender, eventArgs e) { if (MyLabel.Text = PreviousPage.TextBoxText; }
19
ASP.NET v2 Page Framework Cross-page Post Lifecycle P Page Developer Scenario GET PrevPage Initialize Load State and Post Data Load Pre-render Save State Render Unload Raise Changed Events and Postback Event
20
ASP.NET v2 Page Framework Asynchronous 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
21
ASP.NET v2 Page Framework Asynchronous Page Model V1.x: Pages make sync (blocking) Web Service calls Can use IHttpAsyncHandler(not a page) 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
22
ASP.NET v2 Page Framework Asynchronous Page Model 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; }..
23
ASP.NET v2 Page Framework Async Page Lifecycle P Page Developer Scenario GET/POST Initialize Load State and Post Data Load Pre-render Save State Render Unload Async Point: Suspension of lifecycle Raise Changed Events and Postback Event OnPreRenderComplete
24
Call to Action and Summary ScenarioOptions Design, develop and deploy No pre-build required Dynamic compilation Deploy and omit 1 st request penalty Pre-compilation (in-place) Deploy no source code Pre-compilation (allow markup changes) and dynamic compilation Deploy no source code or markup Pre-compilation (no code or markup changes) Deploy and release management Pre-compilation options for fixednames, keyfile..
25
Resources 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
26
Your Feedback is Important! Please Fill Out a Survey for This Session on CommNet
27
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.