ASP.NET Request Processing Internals Abhijit Jana Consultant | Microsoft http://abhijitjana.net
Nov 22, 2014
ASP.NET Request Processing Internals
Abhijit JanaConsultant | Microsofthttp://abhijitjana.net
Agenda
ASP.NET Request
Processing Internals
Role of Web Server
Page Life Cycle
Internal of Web Server
Request Processing
Request Pipeline
Getting Started• Visual Studio IDE has it own Integrated ASP.NET Runtime• ASP.NET Development Server
• WebDev.WebServer20.exe ( CLR 2.0 )• WebDev.WebServer40.exe (CLR 4.0 )
• ASP.NET Development Server Runs on Specific Port
Local Development System
Visual Studio
Web Application
ASP.NET Development ServerWebdev.WebServer20.exe Webdev.WebServer40.exe
Demo
Local Development System
Visual StudioWeb
Application
Local IISWorker Process
Process Request
(w3wp.exe)
Request
Response
Moving to IIS
Key ConceptApplication PoolWorker ProcessWeb FarmWeb Garden
IISApplication
Pool
Worker
Process
Application Pool
Application Pool
Worker
Process
Worker
Process
Web Application
1
Web Application
2
Web Application
3Web
Application 4
w3wp
Application Pool and HTTP.SYS
HTTP.SYS
IIS
Application Pool
W3wp.exe
Application Pool
W3wp.exe
Application Pool
W3wp.exe
ApplicationHost.Config
Demo
Protocol Listener [ HTTP.SYS ]• Protocol Listener is the part of Kernel Level of IIS• Protocol listeners receive protocol-specific requests• send them to IIS for processing• return responses to requestors• It the Kernel mode Protocol stack which listens to the HTTP and HTTPS
Request• Kernel-mode caching• Kernel Mode Queuing
WWW service and WAS• Part of User Level of IIS• World Wide Web Publishing Service (WWW service) and Windows
Process Activation Service (WAS) run as Local System in the same Svchost.exe process– Performance Monitoring– Processing Monitoring– Configuration Management Svchost.exe
World Wide Web Publishing Service (WWW service)
Windows Process Activation Service (WAS)
HTTP.SYS
Svchost.exe
Overall View Of IIS
World Wide Web Publishing Service
(WWW service)
Windows Process Activation Service
(WAS)
HTTP.SYS
Application Pool
ApplicationHost.Config
Looking bit Inside of Request Processing
HTTP.SYS
IIS
Application Pool
W3wp.exe
Application Pool
W3wp.exe
Application Pool
W3wp.exe
HTTP Module
HTTP Handler HTTP Handler
HTTP Module
HTTP Module
HTTP Module
HTTP Module
Svchost.exe
WWW service WAS
Request Processing Continue..• Client Send a Request, HTTP.sys intercepts the request. • HTTP.sys Interacts with WWW Publishing Services and sync
with the related configuration stored in applicationHost.config.
• The WWW Service receives configuration like application pool, virtual directory, site details from applcationHost.config
• WWW Publishing Services gets the request from Http.Sys and passed to WAS
• WAS starts a worker process for the application pool associated with the request was made.
• Workerprocess execute ASP.NET Internals operations• The worker process processes returns a response to
HTTP.sys. • The client receives a response from Server.
Inside Worker Process (w3wp.exe)
W3wp.exeaspnet_isapi.dll
Http Application
HTTP Module
HTTP Handler HTTP Handler
HTTP Module
HTTP Module
HTTP Module
HTTP Module
HTTPRuntime
HTTPProcessRequest
HTTPContext
HTTP Application
HTTP ApplicationFactory.NET
Run
time
Demo
Inside Worker Process (w3wp.exe) cond..
W3wp.exe
Web Server CoreBeginRequest
Modules
Authentication
Authorization
Cache Resolution
Handler
Release State
Update Log
End Request Processing
BasicAuthenticationModule
HttpCacheModule
StaticCompressionModule
DynamicStaticCompressionModule
URL Authorization
Tracing
HTTP Error
HTTP Logging
HTTP PipelineHTTP Module
HTTP Handler HTTP Handler
HTTP Module
HTTP Module
HTTP Module
HTTP Module
• Modules are individual features that the server uses to process requests
• Plug-in / out modules you want on the server or Application Specific.
• customize a server to a specific role in your environment.
• custom modules to replace existing modules or to introduce new features based on application on server specific
• Content Module ( IsapiFilter ,IsapiFilterModule )
• Security Module (BasicAuthenticationModule )
• Caching Module ( HttpCacheModule)• Compression Module
( StaticCompressionModule )
ASP.NET RoutingW3wp.exe
Web Server CoreBeginRequest
Routing Module
Authentication
Authorization
Cache Resolution
Handler
Release State
Update Log
End Request Processing
IHandler
Once done with HTTP Pipeline
Page_PreInit
Page_Init
Load View StateLoad Post Back
DataPage_Load
Page Post back event
Pre Render
Save View State
Render
Unload
ASP.NET Page Life
Cycle
SummaryCl
ient
Sen
d Re
ques
t Server Receives the Request.Request taken care by WWW Services from
HTTP.SYS
Requ
est
com
es t
o W
3wp Loads ISAPI
Deal with HttpApplication, HttpRuntime, HttpContextForward Request for Http Pipeline
HTT
P Pi
pelin
e
Request Passes through number of HTTP Module and reaches to HTTP Handler
Page
Life
Cyc
le
Executes Page Life Cycle Events.Render Content HTMLResponse Back To Client
Resource for further Study• A low-level Look at the ASP.NET Architecture• IIS URL Rewriting and ASP.NET Routing • IIS 7.0 Request Filtering and URL Rewriting • Securely
Implement Request Processing, Filtering, and Content Redirection with HTTP Pipelines in ASP.NET
Q/A
Thank You !Abhijit Jana
Blog : http://abhijitjana.net http://dailydotnettips.com
Twitter : @AbhijitJana