Download presentation
Presentation is loading. Please wait.
Published byVivien Lee Modified over 9 years ago
1
DEV402 Extending the ASP.NET Runtime Jurgen Postelmans Microsoft Regional Director BeLux U2U
2
Agenda Role of the HttpRuntime What is the HttpRuntime The HttpContext class Extending the HttpRuntime HttpModules Global.asax HttpHandlers Hosting the HttpRuntime
3
Using HttpModules and HttpHandlers demo demo
4
Role of the Http Runtime Pluggable, modular architecture Caching, Security, State Management…. Ability to customize and extend ASP.NET Example: Perform dynamic authorization Example: Take over.xml file extension Reduce need for C/C++ ISAPIs Goal: You can do everything in ASP.NET Use any managed language, including VB.NET
5
HTTPRequestHandler ASP.NET Architecture Inside IIS 5.0 INETINFO.EXE (IIS 5.0) aspnet_isapi.dll ASPNET_WP.EXE Worker Process Named pipes http://www.foo.com/bar.aspx
6
ASP.NET Architecture Inside IIS 5.0 HTTP.SYSHTTP.SYS User Mode Kernel Mode ASP.NET Filters Worker Process ASP.NET Filters ASP.NET Filters WASWAS INETINFO metabase AppPool 1 AppPool 2
7
Http Runtime Architecture HttpHandlers HttpModules HttpRuntime.asmx.aspx.ashx OutputCache Authentication SessionState Process Boundary Cache External Session HttpContext
8
HttpContext Everything you needed to know about the current ASP.NET Request but where afraid to ask
9
About HttpContext The glue that ties the pipeline together Encapsulates all request specific data Instance created for each request System.Web.HttpContext “flows” throughout request lifetime Developers can add to HttpContext HttpContext.Items collection Objects then flowed throughout request Exposed via static HttpContext.Current Code must be running on original thread
10
HttpContext Properties NameTypeDescription CurrentHttpContextContext for the current request ApplicationHttpApplicationStateAppliction-wide property bag ApplicationInstanceHttpApplicationApplication Context (Modules) SessionHttpSessionStatePer-client session state RequestHttpRequestThe HTTP Request ResponseHttpResponseThe HTTP Response UserIPrincipalPrincipal information HandlerIHttpHandlerHTTP Handler that will dispatch the call ItemsIDictionaryPer-request property bag ServerHttpServerUtilityURL cracking/sub handlers ErrorExceptionFirst error occured during processing
11
Using HttpContext demo demo
12
Implementing HttpModules Participate in every ASP.NET request
13
HttpModules Enables developers to: Extend the HTTP Pipeline Examine and modify HTTP Requests Used by ASP.NET: External Session State HttpModule Forms Authentication HttpModule Output Cache HttpModule ….
14
HttpRuntime Architecture HttpModules HttpRuntime HttpHandlers.aspx.asmx.ashx OutputCacheOutputCache AuthenticationAuthentication SessionStateSessionState HttpContext Output Cached Page Cache External Session
15
HttpModules What Are Interception Events? Request participation Methods called at specific stages of request HttpRequest HttpResponse available Terminate processing of request HttpApplication.CompleteRequest() Response.End()
16
Per-Request Application Events BeginRequest AuthenticateRequest AuthorizeRequest ResolveRequestCache AquireRequestState PreRequestHandlerExecute Handler Execution PostRequestHandlerExecute ReleaseRequestState UpdateRequestCache EndRequest
17
Creating an HttpModule Class must implement interface: System.Web.IHttpModule Init() Called when module is created Register delegates for runtime events Dispose() public interface IHttpModule { public void Init(HttpApplication application); public void Init(HttpApplication application); public void Dispose(); }
18
Registering an HttpModule 1. Compile into.NET assembly 2. Deploy Into application’s \bin directory or Register in the GAC 3. Register in configuration: <add name=“friendly name” <add name=“friendly name” type=“class, assembly“ /> type=“class, assembly“ />
19
Modules vs Global.asax Functionality of global.asax and modules overlap Global.asax supports extra events like Application_Start and Application_End Session_Start and Session_End
20
Response Filtering Filtering the response stream Cannot be done directly Response stream is read-only Need to implement a custom filter All output generated by ASP.NET will pass through the custom filter Response object writes result through the custom filter. Implemented using Response.Filter property
21
Writing Modules demo demo
22
Implementing HttpHandlers Taking control of the request target
23
What are HttpHandlers ? Are the endpoint for a request They actually process the request and generate the response (HTML, XML,…) Similar to ISAPI Extensions Examples: ASP.NET Page Handler (*.aspx) ASP.NET Service Handler (*.asmx) Server-Side XSL Transformer (*.xml) Dynamic image generation
24
Creating an HttpHandler Class must implement interface: System.Web.IHttpHandler ProcessRequest() ‘Main’ method of the handler IsReusable { get; } Indicates whether pooling is supported public interface IHttpHandler { public void ProcessRequest(HttpContext context); public bool IsReusable(); }
25
Registering an HttpHandler 1. Compile into.NET assembly 2. Deploy Into application’s \bin directory or Register in the GAC 3. Register in configuration: 4. Important: Extension must be mapped in IIS
26
Writing Handler demo demo
27
Writing an Asynchronous Handler demo demo
28
Hosting the HttpRuntime
29
ASP.NET Hosting HttpRuntime is a clean abstraction Enable non-IIS hosting scenarios System.Web.Hosting namespace Scenarios: Pre-generation of.htm for dynamic pages ASP.NET Cassini server (XP Home) See http://www.asp.net/Projects/Cassini/ Download/Default.aspx?tabindex=0&tabid=1 for sample sourcehttp://www.asp.net/Projects/Cassini/ Download/Default.aspx?tabindex=0&tabid=1
30
Hosting ASP.NET demo demo
31
Community Resources http://www.microsoft.com/communities/default.mspx Most Valuable Professional (MVP) http://www.mvp.support.microsoft.com/ Newsgroups Converse online with Microsoft Newsgroups, including Worldwide http://www.microsoft.com/communities/newsgroups/default.mspx User Groups Meet and learn with your peers http://www.microsoft.com/communities/usergroups/default.mspx
32
Suggested Reading And Resources The tools you need to put technology to work! TITLEAvailable Microsoft® ASP.NET Programming with Microsoft Visual C#®.NET Version 2003 Step By Step: 0-7356-1935-6 Today Microsoft Press books are 20% off at the TechEd Bookstore Also buy any TWO Microsoft Press books and get a FREE T-Shirt
33
evaluations evaluations
34
© 2003 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.