ASPNET Pipeline SreedharKoganti
Transcript of ASPNET Pipeline SreedharKoganti
-
8/6/2019 ASPNET Pipeline SreedharKoganti
1/21
ASP.NET Pipeline
(HttpModule andHttpHandler)
Sreedhar Koganti
Microsoft MVP (ASP.NET)http://weblogs.asp.net/skogantiContact: http://weblogs.asp.net/skoganti/contact.aspx
--- http://www.w3coder.com
-
8/6/2019 ASPNET Pipeline SreedharKoganti
2/21
Agenda
Request Process Pipeline architecture intro
Good to know HttpRuntime Architecture
Meet Global.asax, HttpModule
Take advantage of HttpModule
Understand HttpHandler
Meet Lengthy process Life saver
Asynchronous HttpHandlerQ & A
-
8/6/2019 ASPNET Pipeline SreedharKoganti
3/21
Request Process Pipelinearchitecture intro
Request Process Pipelinearchitecture intro
HTTP.SYSHTTP.SYS
Worker process identity (w3wp.exe)Worker process identity (w3wp.exe)
aspnet_isapiaspnet_isapi
User Mode
Kernel Mode
CLR/HttpRuntimeCLR/HttpRuntime
AppDomain
CodeCamp/Pipelinetest.aspx
-
8/6/2019 ASPNET Pipeline SreedharKoganti
4/21
IIS and ASP.NET
.NET extensions are configured to behandled by aspnet_isapi.dll
-
8/6/2019 ASPNET Pipeline SreedharKoganti
5/21
Peal it and see inside thepipeline
-
8/6/2019 ASPNET Pipeline SreedharKoganti
6/21
Architecture
HttpHandlers
HttpModulesHtt
pR
un
time
Htt
pR
un
time
.asmx.asmx .aspx.aspx .ashx.ashx
OutputCacheOutputCache
AuthenticationAuthentication
SessionStateSessionState
Process BoundaryProcess Boundary
Htt
pC
on
tex
t
CodeCamp/Pipelinetest.aspx
-
8/6/2019 ASPNET Pipeline SreedharKoganti
7/21
HttpRuntime is Logical replacement for ISAPI APIHttpRuntime forwards requests to HttpApplication
Here starts the storyHttpRuntime interns calls:
HttpContext
HttpHandler
HttpModule
Architecture
-
8/6/2019 ASPNET Pipeline SreedharKoganti
8/21
. ,HttpModule
Events are fired at several stages in theprocessing of requests and responses pass
through the pipelineYou can handle these events either inHttpApplication (global.asax) or in IHttpModuleinterface
Functionality of global.asax and modulesoverlap
ASP.NET had its own modules
Session State HttpModule
Forms Authentication HttpModule
Output Cache HttpModule
Global.asax supports extra events like
Application_Start and Application_EndSession Start and Session End
-
8/6/2019 ASPNET Pipeline SreedharKoganti
9/21
Global.asax/HttpModule
Demo
P R t A li ti
-
8/6/2019 ASPNET Pipeline SreedharKoganti
10/21
Per-Request ApplicationEvents
BeginRequestAuthenticateRequestAuthorizeRequestResolveRequestCache
AquireRequestStatePreRequestHandlerExecuteTarget Handler ExecutionPostRequestHandlerExecute
ReleaseRequestStateUpdateRequestCacheEndRequest
T k d t f
-
8/6/2019 ASPNET Pipeline SreedharKoganti
11/21
Take advantage ofHttpModule
Class must implement interface:System.Web.IHttpModule
Init()
Called when module is createdRegister delegates for runtime events
Dispose()
public interface IHttpModule {public interface IHttpModule {
public void Init(HttpApplication application);public void Init(HttpApplication application);
public void Dispose();public void Dispose();
}}
R i t i
-
8/6/2019 ASPNET Pipeline SreedharKoganti
12/21
Registering anHttpModule
Compile into .NET assembly
Deploy
Into applications \bin directory or
Register in the GAC
Register in configuration:
-
8/6/2019 ASPNET Pipeline SreedharKoganti
13/21
Real-time HttpModuleexamples
Demo
-
8/6/2019 ASPNET Pipeline SreedharKoganti
14/21
-
8/6/2019 ASPNET Pipeline SreedharKoganti
15/21
Creating anHttpHandler
Class must implement interface:System.Web.IHttpHandler
ProcessRequest()
Main method of the handler
IsReusable { get; }
Indicates whether pooling is supported
public interface IHttpHandler {public interface IHttpHandler {
public void ProcessRequest(HttpContext context);public void ProcessRequest(HttpContext context);
public bool IsReusable();public bool IsReusable();}}
R i t i
-
8/6/2019 ASPNET Pipeline SreedharKoganti
16/21
Registering anHttpHandler
Compile into .NET assembly
Deploy
Into applications \bin directory or
Register in the GAC
Register in configuration:
Important: Extension must be mapped in IIS
type="class, assembly" />
-
8/6/2019 ASPNET Pipeline SreedharKoganti
17/21
Real-time HttpHandlerexamples
Demo
-
8/6/2019 ASPNET Pipeline SreedharKoganti
18/21
Meet Lengthy process Lifesaver Asynchronous
HttpHandler
Same as normal handler in implimentation.
It implements using IHttpAsyncHandler
IhttpAsyncHandler is derived fromIhttpHandler
p s nc an er
-
8/6/2019 ASPNET Pipeline SreedharKoganti
19/21
p sync an erImplimentation
public class ImageAsyncHandler : IHttpAsyncHandler{
public ImageAsyncHandler(){ }public IAsyncResult BeginProcessRequest(HttpContext context,
AsyncCallback cb, object extraData){ }
public void EndProcessRequest(IAsyncResult result){
HttpContext context = (HttpContext)result.AsyncState;
}public bool IsReusable
{get { return true; }
}public void ProcessRequest(HttpContext context){ }
}
-
8/6/2019 ASPNET Pipeline SreedharKoganti
20/21
ea - meIHttpAsyncHandler
examples
Demo
-
8/6/2019 ASPNET Pipeline SreedharKoganti
21/21
Its Your time.Want to learn more? here are some references..
Have Questions: Visit http://forums.asp.net/
See below links for more information onHttpModule/HttpHandler examples:
http://support.microsoft.com/kb/887289
http://aspalliance.com/articleViewer.aspx?aId=442
http://forums.asp.net/thread/1353901.aspx
http://www.codeproject.com/useritems/http-module-ip-security.asp
http://briandela.com/blog/archive/2005/06/29/652.aspx
http://support.microsoft.com/kb/887289http://aspalliance.com/articleViewer.aspx?aId=442http://forums.asp.net/thread/1353901.aspxhttp://www.codeproject.com/useritems/http-module-ip-security.asphttp://briandela.com/blog/archive/2005/06/29/652.aspxhttp://briandela.com/blog/archive/2005/06/29/652.aspxhttp://www.codeproject.com/useritems/http-module-ip-security.asphttp://forums.asp.net/thread/1353901.aspxhttp://aspalliance.com/articleViewer.aspx?aId=442http://support.microsoft.com/kb/887289