您的位置:首页 > 移动开发

ASP.NET Application Life Cycle

2008-05-28 14:45 447 查看
Original Post at http://blogs.msdn.com/tom/archive/2008/05/27/asp-net-application-life-cycle.aspx

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:

Validate the request – checking for malicious markup
Perform URL mapping
BeginRequest event
AuthenticateRequest event
PostAuthenticateRequest event
AuthorizeRequest event
PostAuthorizeRequest event
ResolveRequestCache event
PostResolveRequestCache event
Find the requested resource, if it is a Page, compile the page
PostMapRequestHandler event
AcquireRequestState event
PostAcquireRequestState event
PreRequestHandlerExecute event
Call ProcessRequest on the HttpHandler
PostRequestHandlerExecute event
ReleaseRequestState event
PostReleaseRequestState event
Response filtering
UpdateRequestCache event
PostUpdateRequestCache event
EndRequest event
PreSendRequestHeaders event
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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: