ASP.NET Application Life Cycle

Have you ever wondered about all the stages that an ASP.NET request goes through?  Ever wonder why it is such a performance hit to have a wildcard mapping to map all extensions on your web server to ASP.NET?  This information corresponds to IIS 5.0 and 6.0.  For information on the life cycle in IIS 7.0, see ASP.NET Application Life Cycle Overview for IIS 7.0.  You can also check out the ASP.NET Page Life Cycle Overview for information on what happens once a page is run.

User requests a resource

A request comes into the web server and it will check to see what is mapped to handle the request.  ASP.NET is an ISAPI extension under the web server.

ASP.NET receives the first request for an application

ASP.NET will first create the application domain for this application.  These allow each application to be isolated from each other.  ASP.NET then compiles all the top-level items in the application, if required, including the App_Code folder.

ASP.NET core objects created for the request

ASP.NET will create the Request, Response, and Context objects for the request.  This includes browser information, cookies, headers and everything that the server will respond back to the client with.

HttpApplication is assigned to the request

The application is started by creating the HttpApplication object, taking into account the Global.asax file if it exists.  At this stage, ASP.NET will create any configured modules, such as SessionStateModule to handle Session.

HttpApplication pipeline

The following events occur:

  1. Validate the request – checking for malicious markup
  2. Perform URL mapping
  3. BeginRequest event
  4. AuthenticateRequest event
  5. PostAuthenticateRequest event
  6. AuthorizeRequest event
  7. PostAuthorizeRequest event
  8. ResolveRequestCache event
  9. PostResolveRequestCache event
  10. Find the requested resource, if it is a Page, compile the page
  11. PostMapRequestHandler event
  12. AcquireRequestState event
  13. PostAcquireRequestState event
  14. PreRequestHandlerExecute event
  15. Call ProcessRequest on the HttpHandler
  16. PostRequestHandlerExecute event
  17. ReleaseRequestState event
  18. PostReleaseRequestState event
  19. Response filtering
  20. UpdateRequestCache event
  21. PostUpdateRequestCache event
  22. EndRequest event
  23. PreSendRequestHeaders event
  24. PreSendRequestContent event

Hopefully this will give you a little perspective on all of the different times that you can hook into a request and the different things you can act on.  There are additional things you can do, such as Application_Start events in the global.asax file.  For those and some nice pictures of some of the above data, take a look at the MSDN page here.

Published 27 May 08 06:00 by Tom
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# ASP.NET Debugging : ASP.NET Application Life Cycle said on May 27, 2008 10:19 AM:

PingBack from http://blogs.msdn.com/tom/archive/2008/05/27/asp-net-application-life-cycle.aspx

# DotNetKicks.com said on May 27, 2008 1:09 PM:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# Shail said on May 28, 2008 7:42 AM:

Hi,

I really appreciate that you have explained the entire things in very simple words.

Now just to carry on the discussion, can you please explain these things

1. What are the things which causes an application to restart ? Say change in connection string in Web.Config or Change in Web.Config file

2. What makes the entire worker process restarted ?

3. How IIS can be configured to deliver best performance

My intention is to make a complete knowledge base, where everything related to ASP.NET infrastructure is available.

Thank You,

Shail

# Tom said on May 28, 2008 10:29 AM:

Shail,

Thanks for the comment.  Here are my answers:

1. Numerous things can cause it to restart.  Any changes to any of the files the application depends on will cause it to restart.  The config files are just a few of them

2. Crashes can cause the process to restart, or if it hits one of the health monitoring limits.

3. Configuring IIS really depends on what you are doing with it, take a look at this post for some places to start:

http://blogs.msdn.com/tom/archive/2008/03/25/hangs-and-how-to-solve-them-part-2-queuing.aspx

Keep the questions coming...

# Shail said on May 28, 2008 4:35 PM:

Hi,

Thank you very much for answers.

There are few more questions

1. Is there is any tool which can be just attached to your IIS and it will give you all the information about application performance, even at the page level and of course in graphical way. So that you can find whats wrong with the application. I think thats even better for Administrators. Thats something performance counters and Windows logs can do for you.

2.How can I set my IIS and other ASP.NET process such as Worker process as High Priority processes in my OS. For example, I have other application like anti virus. So I want to achieve the performance from the level of CPU. I wanna instruct my machine that keep the IIS and ASP.NET as the top priority application.

3. Now we have Multi-Core CPUs, is that possible that  I can write my ASP.NET code ( Say business classes ) in such a way, So that the money I paid to have a Multi-Core CPU is utilized.

Thank You,

Shail

# Tom said on May 29, 2008 8:32 AM:

Shail,

For #1, the best we currently have is DebugDiag:

http://www.iis.net/downloads/default.aspx?tabid=34&g=6&i=1286

It does a very nice job bringing everything together.

For #2, take a look at:

http://www.schrockinnovations.com/computerperformance.php

Also, in the performance options, switch to the Advanced tab and change the "Adjust for best performance of:" to Background services.

For #3, ASP.NET will use multi-core for .NET, if you want to write your code to use it more, there are some exciting things coming down the pipe.  Keep checking this blog and I'll write about them soon.

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

Search

This Blog

Syndication

Page view tracker