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.

Download Report

Transcript 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.

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
Build extensibility
ASP.NET page lifecycle
Call backs, cross-page post
Asynchronous pages
ASP.NET V2 Web Application
ASP.NET v1.x
Development Cycles
Design & Develop
ASPX …
CS/VB
App.DLL
Design-time: VS
Pages: Code-behind
Control: Code ‘spit’
Objects: \bin (own dll)
Build: (App.DLL)
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.x Compilation
Page Compilation
File containing separated
code. Designer only.
Class that the page-gen’
inherits from
An (optional) class-name
for the page-gen’ class
<%@ Page codebehind=“wf1.aspx.cs” inherits=“App1.WF1” classname=“MyClass”
Dynamic compile
ASP.MyClass2
ASP.MyClass
AutoAutogenerated
generated
page class
page class
App1.WF..
App1.WF1
Class defined
Class
defined
in codebehind
in codebehind
System.Web.UI.Page
VS Build (pre-compile)
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 v2
Development Cycles
Design & Develop
ASPX …
WSDL, XSD, RESX
CS/VB
DLL
Design-time: VS
Pages: Code-behind
or single file
Control: No code ‘spit’
Deploy Test/
Production
ASPX …
WSDL, XSD, RESX
CS/VB
DLL
Deploy Test/
Production
ASPX …
DLL
Deploy Test/
Production
DLL
Layout: (xcopy, build ..)
Dynamic compilation:
Pre-compilation: W/o source and/or markup
(allows changes)
Runtime: ASP.NET
Dynamic compilation of file ‘types’, (extensible)
Compilation of specialized folders
ASP.NET v2 Compilation
Page Compilation
File containing separated
code
Class that the page-gen
inherits from
An (optional) class-name
for the page-gen class
<%@ 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
MyClass2
MyClass
AutoAutogenerated
generated
page class
page class
Base Class. Final base is System.Web.UI.Page
Dynamic compile
Default2
_Default
AutoAutogenerated
generated
partial class
partial class
Default2
_Default
Partial class
Partial
definedclass
in
defined
in
codefile
codefile
System.Web.UI.Page
ASP.NET v2 Code-Behind
and Compilation
ASP.NET v2 Compilation
Specialized Folders
\WeatherForecastApp
\App_GlobalResources
\App_WebReferences
\App_Code
global.ASAX
\App_Browsers
default.aspx
\App_LocalResources
\App_Themes\Theme
Global Resources
1. Strongly-typed resources
Web
References
2. Service
Shared in
application
1. Folder structure defines type
Bus’Dynamic
Logic, Base
Utilitygeneration
Classes ..
2.
URL&proxy
Compile
assemblythroughout
(or many in order
3.
Consumable
Extends
HttpApplication
in <codeSubDirectories>)
application
1. Single
Application
events
1.
language
per folder
Browser
Capabilities
Page
compilation
2. Can contain ‘non-code’ types
.BROWSER
1. Compiled
onfiles
demand
Compiledand
on demand
2. Batching
dependencies
3. Local resources compiled
4. Theme and master-pages
compiled on demand
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
Pre-compilation
ASP.NET v2 Pre-compilation
Page Allows Updates
<%@ Page codefile=“home.aspx.cs” inherits=“HomePage” classname=“MyPage”
public partial class HomePage : System.Web.UI.Page
Pre-compile
<%@ Page inherits=“HomePage, App_Web_#####” classname=“MyPage”
Dynamic compile
MyPage2
MyPage
AutoAutogenerated
generated
page class
page class
Default2
HomePage
AutoAutogenerated
generated
partial
partial
‘stub’
Default2
HomePage
Partial class
Partial
definedclass
in
defined
in
codefile
codefile
System.Web.UI.Page
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
Custom BuildProvider and
VirtualPathProvider
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
ASP.NET v2 Page Framework
Callback Lifecycle
C
Initialize
GET
C-BK
Control
Developer Scenario
Load
Load State
Pre-render
Save State
Raise Callback Event:
RaiseCallbackEvent
Render
Unload
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” />
ASP.NET v2 Page Framework
Cross-page Post Lifecycle
GET
PrevPage
P
Initialize
Page
Developer Scenario
Load
Load State and
Post Data
Pre-render
Save State
Raise Changed Events
and Postback Event
Render
Unload
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
ASP.NET v2 Page Framework
Asynchronous 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 Framework
Asynchronous 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
Async Page Lifecycle
GET/
POST
P
Initialize
Page
Developer Scenario
Load
Load State and
Post Data
Raise Changed Events
and Postback Event
Async Point: Suspension
of lifecycle
OnPreRenderComplete
Pre-render
Save State
Render
Unload
Call to Action and Summary
Scenario
Options
Design, develop and deploy
No pre-build required
Dynamic compilation
Deploy and omit 1st 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 ..
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
Your Feedback
is Important!
Please Fill Out a Survey for
This 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.