Date post: | 19-Jan-2016 |
Category: |
Documents |
Upload: | dwight-tucker |
View: | 217 times |
Download: | 0 times |
WEB322WEB322ASP.NET Internals: ASP.NET Internals: Under the Covers Under the Covers – Exploring – Exploring Internals, Internals, Page Lifecycle andPage Lifecycle and the the Compilation ModelCompilation Model
Simon CalvertSimon CalvertProgram ManagerProgram ManagerWeb Platform and Tools TeamWeb Platform and Tools TeamMicrosoft CorporationMicrosoft Corporation
AgendaAgenda
ASP.NET compilationASP.NET compilationDevelopment cycles and options:Development cycles and options:
Dynamic compilationDynamic compilation
Pre-compilationPre-compilation
Build extensibility Build extensibility
ASP.NET page lifecycleASP.NET page lifecycleCall backs, cross-page postCall backs, cross-page post
Asynchronous pagesAsynchronous pages
ASP.NET V2 Web ApplicationASP.NET V2 Web Application
Design-time: VSDesign-time: VSPagesPages: Code-behind: Code-behindControlControl: Code ‘spit’: Code ‘spit’ObjectsObjects: \bin (own dll): \bin (own dll)
BuildBuild: (App.DLL): (App.DLL)
ASP.NET v1.xASP.NET v1.xDevelopment CyclesDevelopment Cycles
Design & DevelopDesign & DevelopASPX …ASPX …CS/VBCS/VB
App.DLLApp.DLL
Deploy Test/ProductionDeploy Test/ProductionASPX …ASPX …CS/VBCS/VB
App.DLLApp.DLL
Deploy Test/Deploy Test/ProductionProduction
ASPX …ASPX …(CS/VB)(CS/VB)App.DLLApp.DLL
Layout (xcopy, copy web, build)Layout (xcopy, copy web, build) ASPX …ASPX … : Allows changes : Allows changesCodeCode: Can remove. Changes rebuild App.DLL : Can remove. Changes rebuild App.DLL App.DLLApp.DLL: Pre-built or build: Pre-built or build
Runtime: ASP.NETRuntime: ASP.NETDynamic compilation of known ‘file’ typesDynamic compilation of known ‘file’ typesKnows ‘single-file’ onlyKnows ‘single-file’ only
System.Web.UI.Page
ASP.NET v1.x CompilationASP.NET v1.x CompilationPage CompilationPage Compilation
Class defined in codebehind
App1.WF..
Class defined in codebehind
App1.WF1
VS Build (pre-compile)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 File containing separated code. Designer only.code. Designer only.
File containing separated File containing separated code. Designer only.code. Designer only.
Class that the page-gen’ Class that the page-gen’ inherits frominherits from
Class that the page-gen’ Class that the page-gen’ inherits frominherits from
An (optional) class-name An (optional) class-name for the page-gen’ classfor the page-gen’ class
An (optional) class-name An (optional) class-name for the page-gen’ classfor the page-gen’ class
namespace App1 { public class WF1 : System.Web.UI.Page { .. } }
Base class. Final base is System.Web.UI.PageBase class. Final base is System.Web.UI.PageBase class. Final base is System.Web.UI.PageBase class. Final base is System.Web.UI.PageCode behind class. Namespace Code behind class. Namespace driven by project and folder (C#). driven by project and folder (C#).
Code behind class. Namespace Code behind class. Namespace driven by project and folder (C#). driven by project and folder (C#).
Layout: (xcopy, build ..)Layout: (xcopy, build ..)Dynamic compilationDynamic compilation::Pre-compilationPre-compilation: W/o source and/or markup : W/o source and/or markup (allows changes)(allows changes)
Deploy Test/Deploy Test/ProductionProduction
ASPX …ASPX …WSDL, XSD, RESXWSDL, XSD, RESX
CS/VBCS/VBDLLDLL
Deploy Test/Deploy Test/ProductionProduction
ASPX …ASPX …DLLDLL
Deploy Test/ Deploy Test/ ProductionProduction
DLLDLLDesign-time: VSDesign-time: VSPagesPages: Code-behind : Code-behind or single fileor single fileControlControl: No code ‘spit’: No code ‘spit’
ASP.NET v2ASP.NET v2Development CyclesDevelopment Cycles
Design & DevelopDesign & DevelopASPX …ASPX …
WSDL, XSD, RESXWSDL, XSD, RESXCS/VBCS/VB
DLLDLL
Runtime: ASP.NETRuntime: ASP.NETDynamic compilation of file ‘types’, (extensible)Dynamic compilation of file ‘types’, (extensible)Compilation of specialized foldersCompilation of specialized folders
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
_Default System.Web.UI.Page
Dynamic compile
ASP.NET v2 CompilationASP.NET v2 CompilationPage CompilationPage Compilation
<%@ Page codefile=“default.aspx.cs” inherits=“_Default” classname=“MyClass”
File containing separated File containing separated codecode
File containing separated File containing separated codecode
Class that the page-gen Class that the page-gen inherits frominherits from
Class that the page-gen Class that the page-gen inherits frominherits from
An (optional) class-name An (optional) class-name for the page-gen classfor the page-gen class
An (optional) class-name An (optional) class-name for the page-gen classfor the page-gen class
public partial class _Default : System.Web.UI.Page
Class is ‘partial’. Combined to Class is ‘partial’. Combined to auto-gen’ partial classauto-gen’ partial class
Class is ‘partial’. Combined to Class is ‘partial’. Combined to auto-gen’ partial classauto-gen’ partial class
Base Class. Final base is System.Web.UI.PageBase Class. Final base is System.Web.UI.PageBase Class. Final base is System.Web.UI.PageBase Class. Final base is System.Web.UI.Page
ASP.NET v2 Code-Behind ASP.NET v2 Code-Behind and Compilationand Compilation
ASP.NET v2 CompilationASP.NET v2 CompilationSpecialized FoldersSpecialized Folders
\WeatherForecastApp\WeatherForecastApp
\App_Code\App_Code
global.ASAXglobal.ASAX
Extends HttpApplicationExtends HttpApplication1.1. Application eventsApplication events
Bus’ Logic, Base & Utility Classes ..Bus’ Logic, Base & Utility Classes ..Compile assembly (or many in order Compile assembly (or many in order
in <codeSubDirectories>)in <codeSubDirectories>)1.1. Single language per folderSingle language per folder2.2. Can contain ‘non-code’ typesCan contain ‘non-code’ types
\App_GlobalResources\App_GlobalResources
Global ResourcesGlobal Resources1.1. Strongly-typed resourcesStrongly-typed resources2.2. Shared in applicationShared in application
\App_WebReferences\App_WebReferences
Web Service ReferencesWeb Service References1.1. Folder structure defines typeFolder structure defines type2.2. Dynamic URL proxy generationDynamic URL proxy generation3.3. Consumable throughout Consumable throughout
applicationapplication \App_Browsers\App_Browsers
Browser CapabilitiesBrowser Capabilities1.1. .BROWSER files.BROWSER files2.2. Compiled on demandCompiled on demand
default.aspxdefault.aspx
\App_LocalResources\App_LocalResources
\App_Themes\Theme\App_Themes\Theme
Page compilationPage compilation1.1. Compiled on demandCompiled on demand2.2. Batching and dependenciesBatching and dependencies3.3. Local resources compiledLocal resources compiled4.4. Theme and master-pages Theme and master-pages
compiled on demandcompiled on demand
ASP.NET v2 Pre-compilationASP.NET v2 Pre-compilationScenariosScenarios
No ‘penalty’ for first-time request:No ‘penalty’ for first-time request:In-place pre-compilationIn-place pre-compilation
Deploy to a server:Deploy to a server:No ‘code’ or markup on the serverNo ‘code’ or markup on the server
Allow markup for minor changes, UI layoutAllow markup for minor changes, UI layout
Ship to a third party, IP restriction:Ship to a third party, IP restriction:Package deployed applicationPackage deployed application
Pre-compilationPre-compilation
Auto-generated partial
Default2
Partial class defined in codefile
Default2
Auto-generated partial ‘stub’
HomePage
Partial class defined in codefile
HomePage System.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-compilationASP.NET v2 Pre-compilationPage Allows UpdatesPage Allows Updates
<%@ Page inherits=“HomePage, App_Web_#####” classname=“MyPage”
Dynamic compile
<%@ Page codefile=“home.aspx.cs” inherits=“HomePage” classname=“MyPage”
ASP.NET v2 Build ExtensibilityASP.NET v2 Build ExtensibilityScenariosScenarios
File-based type extensibility: File-based type extensibility: Create custom types from arbitrary file Create custom types from arbitrary file types, e.g. XSD in types, e.g. XSD in \App_Code\App_Code
Create custom handlers, e.g. ASHXCreate custom handlers, e.g. ASHX
Create custom content, e.g. ASCXCreate custom content, e.g. ASCX
Non-file based source extensibility:Non-file based source extensibility:Move web content to a databaseMove web content to a database
CustomCustom BuildProvider and BuildProvider and VirtualPathProviderVirtualPathProvider
ASP.NET v2 Page Framework ASP.NET v2 Page Framework Page LifecyclePage Lifecycle
Methods, events, auto-hookups Methods, events, auto-hookups (Page_): (Page_):
OnPreInitOnPreInit: Dynamic : Dynamic MasterPageFileMasterPageFile, , ThemeThemeOnPreLoad, OnLoadComplete ..OnPreLoad, OnLoadComplete ..InitializeCulture: InitializeCulture: Dynamic Dynamic Culture/UICulture Culture/UICulture code-gen call when code-gen call when attributes definedattributes defined
Partial page lifecycle: Partial page lifecycle: Cross-page posts, control call backs ..Cross-page posts, control call backs ..
Asynchronous pageAsynchronous page
ASP.NET v2 Page Framework ASP.NET v2 Page Framework Callback LifecycleCallback Lifecycle
CCControl Control Developer ScenarioDeveloper Scenario
GETGETC-BKC-BK InitializeInitialize
Load StateLoad State
LoadLoad
Pre-renderPre-render
Save StateSave State
RenderRender
UnloadUnload
Raise Callback Event: RaiseCallbackEvent
ASP.NET v2 Page Framework ASP.NET v2 Page Framework Cross-page PostCross-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” />
ASP.NET v2 Page Framework ASP.NET v2 Page Framework Cross-page Post LifecycleCross-page Post Lifecycle
PPPage Page Developer ScenarioDeveloper Scenario
GETGETPrevPagePrevPage InitializeInitialize
Load State and Load State and Post DataPost Data
LoadLoad
Pre-renderPre-render
Save StateSave State
RenderRender
UnloadUnload
Raise Changed Events Raise Changed Events and Postback Eventand Postback Event
ASP.NET v2 Page FrameworkASP.NET v2 Page FrameworkAsynchronous Page ModelAsynchronous Page Model
3-tier web applications:3-tier web applications:Synchronous pages (v1.x, v2):Synchronous pages (v1.x, v2):
Remote resource (web service, database) is Remote resource (web service, database) is unresponsive threads are blocked unresponsive threads are blocked
Web application may be unresponsive Web application may be unresponsive
Asynchronous pages (v2):Asynchronous pages (v2):Create non-blocking call to access remote Create non-blocking call to access remote resources resources
Isolates issue to pages accessing remote Isolates issue to pages accessing remote resourcesresources
Potential to reduce # threads, improve latency Potential to reduce # threads, improve latency and throughputand throughput
ASP.NET v2 Page FrameworkASP.NET v2 Page FrameworkAsynchronous Page ModelAsynchronous Page Model
V1.x: Pages make sync (blocking) Web V1.x: Pages make sync (blocking) Web Service callsService calls
Can use Can use IHttpAsyncHandlerIHttpAsyncHandler (not a page)(not a page)
V2: New ‘event’ style async pattern V2: New ‘event’ style async pattern Simplifies making async callsSimplifies making async calls
V2: Pages can be async:V2: Pages can be async:‘‘Event’ or BeginXXXX/EndXXXX stylesEvent’ or BeginXXXX/EndXXXX styles
ASP.NET v2 Page FrameworkASP.NET v2 Page FrameworkAsynchronous Page ModelAsynchronous 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>
ASP.NET v2 Page Framework ASP.NET v2 Page Framework Async Page LifecycleAsync Page Lifecycle
PPPage Page Developer ScenarioDeveloper ScenarioGET/GET/
POSTPOSTInitializeInitialize
Load State and Load State and Post DataPost Data
LoadLoad
Pre-renderPre-render
Save StateSave State
RenderRender
UnloadUnload
Async Point: Suspension Async Point: Suspension of lifecycleof lifecycle
Raise Changed Events Raise Changed Events and Postback Eventand Postback Event
OnPreRenderCompleteOnPreRenderComplete
Call to Action and SummaryCall to Action and Summary
Scenario OptionsDesign, develop and deployDesign, develop and deploy
No pre-build requiredNo pre-build required
Dynamic compilationDynamic compilation
Deploy and omit 1Deploy and omit 1stst request request penaltypenalty
Pre-compilation (in-place)Pre-compilation (in-place)
Deploy no source codeDeploy no source code Pre-compilation (allow markup Pre-compilation (allow markup changes) and dynamic compilationchanges) and dynamic compilation
Deploy no source code or Deploy no source code or markupmarkup
Pre-compilation (no code or markup Pre-compilation (no code or markup changes)changes)
Deploy and release Deploy and release managementmanagement
Pre-compilation options for Pre-compilation options for fixednames, keyfile ..fixednames, keyfile ..
ResourcesResources
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
Your FeedbackYour Feedbackis Important!is Important!Please Fill Out a Survey forPlease Fill Out a Survey forThis Session on CommNetThis 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.