Upload
icubesystem
View
87
Download
0
Tags:
Embed Size (px)
Citation preview
Http Pipeline
Agenda
● Revisit Process & Thread
● Http Pipeline Modes
● Http Pipeline Objects
● Http Pipeline Extensibility
Thread, Process and AppDomain
Threads in a Process
OS has many processes and a process has many threads
Processes are resource intensive
OS runs processes in isolations mode to provide security,
reliability and availability
IPC is slow
AppDomains in a Process
IIS Webserver is a Process
Process is overloaded if apps are hosted
Error in a app brings down entire Web Server process
Application Domains provide security, reliability and
availability
CLR controls AppDomains and they are isolated
Each .NET application runs under AppDomain
Failure of an app does not impact other apps
Pipeline Modes
Classic Mode - IIS5+
Integrated Mode - IIS7+
Classic Mode
pipe
inetinfo.exe
Classic Mode
It only works with ISAPI extensions and ISAPI filters.
ASP.NET modules can’t control/extend certain areas of IIS request execution like
inetinfo.exe.
ASP.NET featuers like modules/handlers/etc are not available for Non-ASP.NET apps.
IIS treats ASP.NET as an external plugin instead of its part.
Integrated Mode
Pipeline Object Model
Pipeline - Inside
HttpContext - Intro
Instance per request
Request specific data
Application specific data
Accessible in different layers including Handlers and Modules
HttpContext - Properties
Hands On
HttpContext - Accessing its properties in business class
HttpContext - Generating Text Response
Homework
HttpContext - Creating Cookies
HttpContext - Generating csv file
Pipeline Extensibility
HttpApplication
Modules
Handlers
HttpApplication - Global.asax
Entry class of a request
Repository of globally resources like Application, Session, Cache
Contains events of application and page lifecycle
Using global.asax, default behavior of application/request can be changed
global.asax is optional
Any change on global.asax raises signal to restart an application
HttpApplication - Members
HttpApplication - Events
HttpApplication - Overridable Methods
HttpApplication - Advance
Application_OnStart and Application_OnEnd are raised only once during an application’s lifetime
Request, Response, and Session properties are not available in Init and Dispose methods
Events must be declared with following pattern: Application_EventName
global.asax file can handle events published by any modules in the request and events must be
declared with following pattern: FriendlyModuleName_EventName. Session_OnStart and
Session_OnEnd are part of Session module and defined in global.asax to cleanup session values.
Hands On
HttpApplication - Request/Response Time
Handlers
Handlers are classes that implements IHttpHandler interface and configured in web.config
Handlers are .ashx file declared with @WebHandler directive - It automatically calls already
registered SimpleHandlerFactory
Handlers are .aspx file declared with @Page directive - It automatically calls with already
registered PageHandlerFactory
In Classic mode [IIS 6 and earlier], URI path must be mapped for aspnet_isapi.dll
Handlers generates customized responses
Common Handlers are .aspx, .ashx, .asmx
Handlers - Use Cases
Non-mapped handlers can respond to any file name extension
Use Async Handler that depends on external services because thread is not blocked and
threadpool able to accept more requests.
Customized response that basically does not contain HTML like RSS feed
On demand, content manipulations like Image resize
Handlers - Implementation
IsReusable = true, HttpHandlerFactory pools those handler objects that improves performance
IsReusable = false, HttpHandlerFactory always creates new handler instance
IsReusable = true, not recommended if your handler generates response based on user/request
type
By Default, IsReusable = false for standard handlers like .aspx, .asmx, .ashx
Handlers - Classic Mode Configuration
Handlers - Integrated Mode Configuration
HandlerFactory - Customization
Handler Factories are classes that implements IHttpHandlerFactory interface and configured in
web.config just like handlers
Factories controls on processing requests by creating different handlers on runtime conditions.
HandlerFactory configuration is equivalent to Handler configuration.
HandlerFactory receives requests and forward requests to appropriate handlers
Hands On
Http Handler - Config
Http Handler - ashx
Http Handler - aspx
Homework
Http Handler - Async
HandlerFactory - change handler based on condition
Modules
Modules are classes that implements IHttpModule interface and configured in web.config
Modules are application specific while Handlers are extension specific. A module is invoked for all
requests/responses
Modules are called on every request as part of request pipeline
Modules have access to life cycle events throughout the request
Modules examine requests and perform appropriate actions. They can allow to modify response
A few ASP.NET modules are Session, Caching, Forms Authentication.
Modules - Use Cases
Custom headers/footers
Rewrite Requests - basically rewrite urls
Security as Modules are called for all requests
Stats and Logging
Module - Implementation
Modules are always pooled
Modules can be deployed at machine level. High reusability compared to global.asax
Modules - Classic Mode Configuration
Modules - Integrated Mode Configuration
Hands On
Http Module - Ip Address Restriction
Http Module - Request Logging
Homework
HttpModule - Common Footer
HttpModule - Rewrite Url
Questions