Download presentation
Presentation is loading. Please wait.
2
Understanding ASP.NET Under The Covers
Miguel A. Castro Architect IDesign Level 200
3
Agenda Defining ASP.NET Terms & Buzzwords
A Request-to-Response Walkthrough Additional Technologies Summary
4
Your Speaker Miguel A. Castro ineta
.NET Architect, Developer, & Trainer Microsoft MVP ASP Insider Member of the INETA Speakers Bureau Conference Speaker Creator of CodeBreeze In IT business since 1986 ineta
5
Agenda Defining ASP.NET Terms & Buzzwords
A Request-to-Response Walkthrough Additional Technologies Summary
6
Classic ASP Interpreted language
Included embedded scripting code mixed into HTML Limited to VBScript Ran in the same process as IIS Inherently not scalable (needed MTS) End of line
7
Walking Upright Designed by Scott Guthrie & Mark Anders
Early iteration of ASP.NET Originally known as XSP Not .NET-related – Java based ! Became ASP+ with the design of the CLR Rewritten in C# Renamed when .NET branding introduced End of line
8
Not a language ! What is ASP.NET
A framework for developing and delivering information & applications on the web. Known primarily as a page framework. A complete Request/Response management system. Can handle and respond to all sorts of requests on the Internet (or an Intranet). Not a language ! End of line
9
Characteristics of ASP.NET
Runs under its own worker process. No longer tied to IIS. Code execution managed by CLR. Code-Behind model allows code separation. Includes state handling facilities. Provides caching functionality. End of line
10
Agenda Defining ASP.NET Terms & Buzzwords
A Request-to-Response Walkthrough Additional Technologies Summary
11
Commonly Used Terms Request Response ASP.NET Pipeline
An HTTP query initiated by a client to a server for the purpose of performing some action. Response A stream of information sent back to a client from the HTTP server that processed the client’s request. ASP.NET Pipeline A series of extensible functionality points which continue the process of a request in order to eventually obtain a response. End of line
12
Commonly Used Terms Page Lifecycle Control Model
Another series of functionality points that form the process of converting an ASPX page to HTML output. The entire page lifecycle occurs between two pipeline points. Control Model The heart of how ASP.NET builds HTML from compiled classes that represent visual components. End of line
13
Agenda Defining ASP.NET Terms & Buzzwords
A Request-to-Response Walkthrough Additional Technologies Summary
14
What Everyone Sees Now the long version… Desktop Browser
Web Server (IIS) Convert ASPX to HTML Rendered HTML Now the long version… End of line
15
Getting it to .NET (the low level stuff)
Kernel Mode Driver: Http API used by IIS Web Server (IIS) Web Server (IIS) Convert ASPX to HTML http.sys Worker Process started (one per pool) and if needed, AppDomain is created. Worker Process (w3wp.exe) – (one per app pool) aspnet_isapi.dll Attached to the extension of the request. Unmanaged DLL that loads the CLR and routes requests to the managed runtime classes via COM-compliant interfaces. AppDomain (one per site/VD) ISAPIRuntime (ProcessRequest method) HttpRuntime. ProcessRequest Request sent to the ASP.NET runtime for processing. End of line
16
HttpRuntime.ProcessRequest
ASP.NET Takes Over HttpRuntime.ProcessRequest Accessible from now until the end of the request processing. Accessible through HttpContext.Current HttpContext created. This serves as an entry point into the request, response, and other accessible variables. Each AppDomain manages multiple instances so they do not conflict with each other (different users or same user with more than one request). An HttpApplication instance is created. HttpApplication This is where it starts to mean something to you, the developer. Init method starts pipeline processing. End of line
17
Entering the Pipeline HttpApplication
Pipeline kicked off in the Init method. HttpApplication BeginRequest Performs event processing. AuthenticateRequest / Post AuthorizeRequest / Post Checks hooks from Global.asax class. ResolveRequestCache / Post Checks hooks from external HTTP Modules. MapRequestHandler / Post AcquireRequestState / Post PreRequestHandlerExecute / Post ReleaseRequestState / Post UpdateRequestCache / Post LogRequest / Post EndRequest PreSendRequestHeaders PreSendRequestContent End of line
18
Entering the Pipeline HttpApplication BeginRequest
AuthenticateRequest / Post AuthorizeRequest / Post ResolveRequestCache / Post MapRequestHandler / Post AcquireRequestState / Post PreRequestHandlerExecute / Post ReleaseRequestState / Post UpdateRequestCache / Post LogRequest / Post EndRequest PreSendRequestHeaders PreSendRequestContent End of line
19
Pipeline Events of Interest
HttpApplication Provide URL-Rewriting functionality. BeginRequest AuthenticateRequest / Post Repopulate HttpContext.Current.User with stored principal. Page authentication occurs here. AuthorizeRequest / Post ResolveRequestCache / Post MapRequestHandler / Post AcquireRequestState / Post PreRequestHandlerExecute / Post Determine whether to use cached response. ReleaseRequestState / Post UpdateRequestCache / Post Any event can be hooked in Global.asax or in an HTTP Module. LogRequest / Post EndRequest PreSendRequestHeaders PreSendRequestContent End of line
20
MyModule : IHttpModule
HTTP Modules Classes that implement IHttpModule. MyModule : IHttpModule Delegate-based Properties in HttpApplication instance can be wired up. Method functionality equivalent to hooking event in Global.asax Event hooks in modules checked during pipeline processing. End of line
21
ASP.NET HTTP Modules of Interest
WindowsAuthenticationModule FormsAuthenticationModule UrlAuthenticationModule FileAuthorizationModule ServiceModel SessionStateModule OutputCacheModule AuthenticateRequest AuthenticateRequest EndRequest AuthorizeRequest AuthorizeRequest PostAuthenticateRequest AcquireRequestState AcquireRequestState ReleaseRequestState EndRequest End of line
22
Any level in the Config chain
Module Installation Any level in the Config chain You do know what the Config chain is, right? End of line
23
The Process Continues HttpApplication Just before this event: Proper HTTP Handler located based on request’s extension. BeginRequest AuthenticateRequest / Post Handlers provide necessary processing in order to create a response. AuthorizeRequest / Post ResolveRequestCache / Post MapRequestHandler / Post AcquireRequestState / Post PreRequestHandlerExecute / Post ReleaseRequestState / Post UpdateRequestCache / Post LogRequest / Post EndRequest PreSendRequestHeaders PreSendRequestContent End of line
24
MyHandler : IHttpHandler
HTTP Handlers Classes that implement IHttpHandler. Determines if the handler instance can be reused by another request. MyHandler : IHttpHandler Functionality assigned to this particular handler. Remember the HttpContext contains all accessible variables, including Response. End of line
25
HTTP Handler Factories
Can also implement IHttpHandlerFactory. Allows the instantiation of any handler based on specific conditioning scenarios. MyHandlerFactory : IHttpHandlerFactory End of line
26
Characteristics of an HTTP Handler
Access to current HttpContext. Request is in there (as is the Response) ! Handlers are wired to extensions (aspx, etc.). Every handler is responsible for what the response is going to be for a request. ASPX requests expect an HTML response. Config requests expect a “forbidden” response. End of line
27
Handler Execution HttpApplication BeginRequest
AuthenticateRequest / Post AuthorizeRequest / Post The determined handler is processed between the PreRequestHandlerExecute and PostRequestHandlerExecute. ResolveRequestCache / Post MapRequestHandler / Post AcquireRequestState / Post PreRequestHandlerExecute / Post ReleaseRequestState / Post UpdateRequestCache / Post LogRequest / Post EndRequest PreSendRequestHeaders PreSendRequestContent End of line
28
Any level in the Config chain
Handler Installation Handler factory that returns and executes the handler that will convert an ASPX page to HTML output. Any level in the Config chain End of line
29
The PageHandlerFactory Class
Implements IHttpHandlerFactory. GetHandler method returns an IHttpHandler in the form of System.Web.UI.Page-derived class hierarchy. Page class implements IHttpHandler. Page class inherits from Control. Control contains events/methods for the “Page Event Lifecycle”. PageHandlerFactory creates a class structure out of your request. End of line
30
Page Class Structure Created by the PageHandlerFactory class
Follows the structure of an ASP.NET Server Control. Referred to as Page-Gen Class. Created by the PageHandlerFactory class Virtual class created from ASPX page. Controls created based on ASPX content. inherits Partial class with control declarations (class name same as code-behind). partials with Code-behind class is other side of partial class. This is why you can tap into events from your code-behind. inherits ProcessRequest method calls lifecycle events in Control. System.Web.UI.Page inherits implements System.Web.UI.Control IHttpHandler End of line
31
Page Class Structure Created by the PageHandlerFactory class
Virtual class created from ASPX page. inherits Partial class with control declarations (class name same as code-behind). partials with Code-behind class is other side of partial class. inherits System.Web.UI.Page inherits implements System.Web.UI.Control IHttpHandler End of line
32
Virtual Class Created from ASPX content
Determines language to be used to generate page-gen class. Specifies the partial class to serve as the code-behind. Optional: Name of the code-file for Visual Studio. End of line
33
Virtual Class Created from ASPX content LiteralControl
Converted to instances of System.Web.UI.LiteralControl that are added to the control tree of this class. Remember, this class will ultimately inherit from System.Web.UI.Control LiteralControl LiteralControl LiteralControl LiteralControl LiteralControl End of line
34
Program code directly added to virtual class.
Created from ASPX content LiteralControl LiteralControl Program code directly added to virtual class. LiteralControl LiteralControl LiteralControl LiteralControl LiteralControl End of line
35
Virtual Class Created from ASPX content LiteralControl
Converted to instances of the corresponding server control class for each of these control tags, that will be added to the control tree of this class. LiteralControl The Form control instance is placed directly in the control tree of the class being created; while the TextBox and Label controls are added to the control tree of the Form control. LiteralControl LiteralControl LiteralControl LiteralControl LiteralControl End of line
36
Virtual Class Created from ASPX content LiteralControl
“asp” tag-prefix located in config file or Register directive. LiteralControl Class with tag name located in appropriate namespace and assembly. LiteralControl LiteralControl LiteralControl LiteralControl LiteralControl End of line
37
Remember: this class “ultimately” inherits from System.Web.UI.Page
Virtual Class Created from ASPX content __PAGE System.Web.UI.Page LiteralControl ctrl0 System.Web.UI.LiteralControl LiteralControl Function Code Remember: this class “ultimately” inherits from System.Web.UI.Page ctrl1 System.Web.UI.LiteralControl form1 System.Web.UI.HtmlControls.HtmlForm LiteralControl ctrl2 System.Web.UI.LiteralControl Control IDs TextBox1 System.Web.UI.WebControls.TextBox LiteralControl ctrl3 System.Web.UI.LiteralControl LiteralControl Label1 System.Web.UI.WebControls.Label ctrl4 System.Web.UI.LiteralControl LiteralControl ctrl5 System.Web.UI.LiteralControl LiteralControl End of line
38
This is the next class you’ll see now.
Virtual Class Created from ASPX content LiteralControl LiteralControl This is the next class you’ll see now. LiteralControl LiteralControl LiteralControl LiteralControl LiteralControl End of line
39
Page rendering with Trace
11/29/2018 7:58 AM demo If you would like to host your demo on the Virtual Server, please use the myVPC demo slide, not this slide. Page rendering with Trace © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
40
Page Class Structure Created by the PageHandlerFactory class
Virtual class created from ASPX page. inherits Partial class with control declarations (class name same as code-behind). partials with Code-behind class is other side of partial class. inherits System.Web.UI.Page inherits implements System.Web.UI.Control IHttpHandler End of line
41
Notice the name is the same as the page’s code-behind class.
Partial Class Base for virtual class and partial to code-behind Notice the name is the same as the page’s code-behind class. End of line
42
Page Class Structure Created by the PageHandlerFactory class
Virtual class created from ASPX page. inherits Partial class with control declarations (class name same as code-behind). partials with Code-behind class is other side of partial class. inherits System.Web.UI.Page inherits implements System.Web.UI.Control IHttpHandler End of line
43
Inheriting from Page gives you access to a control’s event lifecycle.
Code-Behind Class Other side of the Control Declarations class Inheriting from Page gives you access to a control’s event lifecycle. End of line
44
Page Class Structure Created by the PageHandlerFactory class
Virtual class created from ASPX page. Remember, this entire class hierarchy is the handler returned by the PageHandlerFactory class. It is the HttpApplication pipeline that calls ProcessRequest, kicking off the Page Lifecycle. inherits Partial class with control declarations (class name same as code-behind). ProcessRequest comes from here. It is from there that the lifecycle events are called. Events for the lifecycle come from here. partials with Code-behind class is other side of partial class. inherits System.Web.UI.Page inherits implements System.Web.UI.Control IHttpHandler End of line
45
Page (Control) Lifecycle
Complete List PreInit Init InitComplete CreateChildControls (IsPostBack) LoadViewState/LoadControlState IPostBackDataHandler.LoadPostData PreLoad Load IPostBackDataHandler.RaisePostBackChangedEvent IPostBackEventHandler.RaisePostBackEvent LoadComplete CreateChildControls (!IsPostBack) PreRender DataBind PreRenderComplete SaveViewState/SaveControlState Render Unload End of line
46
Most Commonly Known Points
Initialize: OnInit method and Init event Begin tracking ViewState: TrackViewState method Postback only Load View State: LoadViewState method Load Postback Data: IPostBackDataHandler.LoadPostdata method Load: OnLoad method and Load event Raise Changed Events: IPostBackDataHandler.RaisePostBackChangedEvent method Raise Postback Event: IPostBackEventHandler.RaisePostBackEvent method PreRender: OnPreRender method and PreRender event Save View State: SaveViewState method Render: Render method Unload: OnUnload method and Unload event End of line
47
Control Rendering Activated through the Control class’ Render method.
Each control is designed to output something to the response buffer. Most controls output HTML. Some controls contain others in their tree. Control rendering involves recursively rendering child controls. Controls don’t need to output anything ScriptManager End of line
48
Getting a Response “Rendering” uses an HtmlTextWriter stored in the Response object. Response object is part of HttpContext. Writer sent into Render method. After pipeline complete, contents returned up the chain to aspnet_isapi.dll then http.sys. Results viewed on browser. End of line
49
Agenda Defining ASP.NET Terms & Buzzwords
A Request-to-Response Walkthrough Additional Technologies Summary
50
Postbacks Invoked by controls on form that trigger the form to “post”.
Another HTTP Request, but of a post-type. Certain lifecycle methods only invoked on postback only. In a postback, the Request object’s Form property contains posted data from HTML elements (using their client IDs).
51
Postbacks Initialize: OnInit method and Init event
Begin tracking ViewState: TrackViewState method Postback only Load View State: LoadViewState method Load Postback Data: IPostBackDataHandler.LoadPostdata method Load: OnLoad method and Load event Raise Changed Events: IPostBackDataHandler.RaisePostBackChangedEvent method Raise Postback Event: IPostBackEventHandler.RaisePostBackEvent method PreRender: OnPreRender method and PreRender event Save View State: SaveViewState method Render: Render method Unload: OnUnload method and Unload event End of line
52
ASCX User Controls Register directive defines tag prefix and name for user control. src points to an ascx file in the current web application. During parsing, virtual class is built just like a page, except the base is called UserControl. Also, added to Page’s Controls collection. UserControl also inherits from Control but does NOT implement IHttpHandler. Usage in an ASPX page (or another ASCX control) is just like a server control. End of line
53
Master Pages Code-Behind class inherits from MasterPage, which inherits from UserControl. Master directive similar to a Page directive. ASPX page points to a master page file. End of line
54
Master Pages Control that specifies content to be defined in an ASPX page. Control that wraps content. Each Content control corresponds to a ContentPlaceHolder control. End of line
55
Master Pages Desktop Browser Browse to Default.aspx Web Server (IIS)
PageHandlerFactory commences building of virtual class. MasterPageFile attribute encountered. Parsing shifts to master page file and code-behind. Control tree build and added to virtual class. Parsing returns to ASPX page and Content controls turned to code. Each Content control added to the Controls collection of corresponding ContentPlaceHolder control. End of line
56
Note: you cannot browse directly to an ASCX control or a Master page.
Direct Browsing Note: you cannot browse directly to an ASCX control or a Master page. End of line
57
SimpleHandlerFactory in charge of returning HTTP Handler.
ASHX Handlers SimpleHandlerFactory in charge of returning HTTP Handler. End of line
58
ProcessRequest called in the pipeline as always.
ASHX Handlers PageHandlerFactory: Parses ASPX file, building virtual class as an HTTP Handler, with ProcessRequest kicking off page lifecycle. SimpleHandlerFactory: Takes this handler code and returns is as HTTP Handler. ProcessRequest called in the pipeline as always. End of line
59
Themes & Skins Contain server control declarations (without IDs) whose properties overwrite those declared on the ASPX page. Control “registration” applies. Either in skin file or in config file. Applied just before Init lifecycle event. Programmatic application MUST be made in PreInit event. Application using Theme attribute occurs last. Application using StyleSheetTheme attribute occurs first. End of line
60
ASP.NET Ajax More interactive model.
Uses JavaScript to invoke Ajax requests. Web Service (WCF) technology can be used to handle response. Ships with controls and components that encapsulate functionality. Ajax Control Toolkit – ships separately Community driven and supported Undergoes Microsoft Scrutiny Better user experience. End of line
61
ASP.NET MVC Process nearly identical to conventional ASP.NET.
It’s still ASP.NET Uses a URL routing engine to parse URLs and invoke appropriate classes. Pipeline is intercepted by a module tapping into PostResolveRequestCache event. Request is picked up by another handler for processing. Controller classes are sought out and processed (similar to code-behind classes). Appropriate Views parsed and rendered. End of line
62
Why Custom Modules Background processes URL rewriting
Identity persistence for custom providers (or any other kind of persistence) Benchmarking
63
Why Custom Handlers Image watermarking Dynamic image generation
RSS output generation File denial or protection
64
Tips & Tricks Use your own base page to house common functionality.
If overriding On{event} methods, remember that the event-wire-up methods in code-behind fire when you call base On{event}. Example: override OnLoad in a base class, Page_Load in code-behind gets called when you call base.OnLoad. Use <page pageBaseType= demo Register your server controls in your Web.Config file. Eliminates repeat registrations in ASPX & ASCX files. Eliminates registrations in Skin files. End of line
65
Tips & Tricks Remove HTTP Modules that you don’t need
If file protection necessary, add file extension (ZIP) to registered extensions in IIS. Bring them into the pipeline for protection and controlled exposure. Presentation available on my site. End of line
66
Tips & Tricks Turn ViewState off in controls that don’t need them – especially grids. In 4.0 the model can be reversed. More compact in 4.0. Override LoadPageStateFromPersistenceMedium & SavePageStateToPersistenceMedium to alter where and how ViewState is saved.
67
Tips & Tricks Deployment Mode Way Advanced In <system.web>
<deployment retail=“true” /> Turns debugging, tracing, and detailed errors OFF Machine.Config ONLY Way Advanced PageParserFilter abstract base class Lets you govern the behavior of the ASP.NET Page Parser
68
demo Various tips & tricks 11/29/2018 7:58 AM
If you would like to host your demo on the Virtual Server, please use the myVPC demo slide, not this slide. Various tips & tricks © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
69
Agenda Defining ASP.NET Terms & Buzzwords
A Request-to-Response Walkthrough Additional Technologies Summary
70
What To Take Away From This
ASP.NET does much more than serve pages. Decoupled architecture allows flexible hosting. Pipeline and Event cycle – two different things. Extensible architecture allows opportunities for interception and alteration. Module and Handler model enforce encapsulation and reusability. Be mindful of how much is happenning behind the scenes. End of line
71
References Great Wikipedia entry Article: How ASP.NET Works
Article: How ASP.NET Works Code Magazine – Nov/Dec 2005 Rick Strahl
72
References Article: Truly Understanding ViewState
Dave Reed Understanding ASP.NET Internals Rob Howard
73
References Essential ASP.NET 2.0 My Site & Email: www.codeplex.com
Addison-Wesley Fritz Onion & Keith Brown My Site &
74
Tech-Ed 2009 is NOT producing a DVD
IMPORTANT: Tech-Ed 2009 is NOT producing a DVD
75
Resources www.microsoft.com/teched www.microsoft.com/learning
Sessions On-Demand & Community Microsoft Certification & Training Resources Resources for IT Professionals Resources for Developers Microsoft Certification and Training Resources
76
Complete an evaluation on CommNet and enter to win!
77
11/29/2018 7:58 AM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.