对比刚才的顺序,会发现Application_Start及Init没有再次被调用,也印证了文章前面提到的一些结论 (Application_Start在整个asp.net应用生命周期内只触发一次),而且从最后的三个输出能知道:应用程序关闭时 Application_Disposed,Dispose,Application_End按顺序调用.
再"重新"浏览(指web Server重启)一下正常访问的页面,在不出错也不回发的情况下,顺序如下:
2010-03-28 15:08:11 513 Application_Start
2010-03-28 15:08:11 591 Init
2010-03-28 15:08:11 591 Application_BeginRequest
2010-03-28 15:08:11 591 Application_AuthenticateRequest
2010-03-28 15:08:11 591 Application_PostAuthenticateRequest
2010-03-28 15:08:11 606 Application_AuthorizeRequest
2010-03-28 15:08:11 606 Application_PostAuthorizeRequest
2010-03-28 15:08:11 606 Application_ResolveRequestCache
2010-03-28 15:08:11 606 Application_PostResolveRequestCache
2010-03-28 15:08:11 622 Application_PostMapRequestHandler
2010-03-28 15:08:11 637 Application_EndRequest
2010-03-28 15:08:11 637 Application_PreSendRequestHeaders
2010-03-28 15:08:11 637 Application_PreSendRequestContent
2010-03-28 15:08:11 637 Application_BeginRequest
2010-03-28 15:08:11 637 Application_AuthenticateRequest
2010-03-28 15:08:11 653 Application_PostAuthenticateRequest
2010-03-28 15:08:11 653 Application_AuthorizeRequest
2010-03-28 15:08:11 653 Application_PostAuthorizeRequest
2010-03-28 15:08:11 653 Application_ResolveRequestCache
2010-03-28 15:08:11 653 Application_PostResolveRequestCache
2010-03-28 15:08:11 653 Application_PostMapRequestHandler
2010-03-28 15:08:11 653 Session_Start
2010-03-28 15:08:11 653 Application_AcquireRequestState
2010-03-28 15:08:11 653 Application_PostAcquireRequestState
2010-03-28 15:08:11 653 Application_PreRequestHandlerExecute
2010-03-28 15:08:11 669 Page_PreInit
2010-03-28 15:08:11 684 Page_Init
2010-03-28 15:08:11 684 Page_InitComplete
2010-03-28 15:08:11 684 Page_PreLoad
2010-03-28 15:08:11 684 Page_Load
2010-03-28 15:08:11 684 Page_LoadComplete
2010-03-28 15:08:11 684 Page_PreRender
2010-03-28 15:08:11 684 Page_SaveStateComplete
2010-03-28 15:08:11 700 Page_Unload
2010-03-28 15:08:11 700 Application_PostRequestHandlerExecute
2010-03-28 15:08:11 700 Application_ReleaseRequestState
2010-03-28 15:08:11 700 Application_PostReleaseRequestState
2010-03-28 15:08:11 700 Application_UpdateRequestCache
2010-03-28 15:08:11 700 Application_PostUpdateRequestCache
2010-03-28 15:08:11 700 Application_EndRequest
2010-03-28 15:08:11 700 Application_PreSendRequestHeaders
2010-03-28 15:08:11 700 Application_PreSendRequestContent
2010-03-28 15:08:11 793 Application_BeginRequest
2010-03-28 15:08:11 793 Application_AuthenticateRequest
2010-03-28 15:08:11 793 Application_PostAuthenticateRequest
2010-03-28 15:08:11 793 Application_AuthorizeRequest
2010-03-28 15:08:11 793 Application_PostAuthorizeRequest
2010-03-28 15:08:11 793 Application_ResolveRequestCache
2010-03-28 15:08:11 793 Application_PostResolveRequestCache
2010-03-28 15:08:11 809 Application_PostMapRequestHandler
2010-03-28 15:08:11 809 Application_AcquireRequestState
2010-03-28 15:08:11 809 Application_PostAcquireRequestState
2010-03-28 15:08:11 809 Application_PreRequestHandlerExecute
2010-03-28 15:08:11 825 Application_PostRequestHandlerExecute
2010-03-28 15:08:11 825 Application_ReleaseRequestState
2010-03-28 15:08:11 840 Application_PostReleaseRequestState
2010-03-28 15:08:11 949 Application_UpdateRequestCache
2010-03-28 15:08:11 949 Application_PostUpdateRequestCache
2010-03-28 15:08:11 965 Application_EndRequest
2010-03-28 15:08:11 981 Application_PreSendRequestHeaders
2010-03-28 15:08:11 981 Application_PreSendRequestContent
哇!原来一个页面访问下来,会调用到这么多的方法,怪不得很多高并发的大型网站,通常都要自己写一个精减的HttpHandler用来取代Page做为基类,以期望获得更好的性能
最后:我们在做网站开发时,不可能只用到Page页,很多时候还会用到UserControl(用户自定义控件),先看下它的继承关系,比如我们创建了一个TestUserControl的用户控件
TestUserControl --> UserControl ---> TemplateControl --> Control
最终在Control类的定义下,可以看到
这似乎表明用户控件中,应该有Page_Init,Page_Load,Page_Unload...等事件,通常我们只用到Init,Load事件,如果加入一个用户控件后,整个生命周期就更复杂了:
2010-06-12 15:35:28 042 Application_Start
2010-06-12 15:35:28 072 Init
2010-06-12 15:35:28 072 Application_BeginRequest
2010-06-12 15:35:28 082 Application_AuthenticateRequest
2010-06-12 15:35:28 082 Application_PostAuthenticateRequest
2010-06-12 15:35:28 092 Application_AuthorizeRequest
2010-06-12 15:35:28 102 Application_PostAuthorizeRequest
2010-06-12 15:35:28 102 Application_ResolveRequestCache
2010-06-12 15:35:28 112 Application_PostResolveRequestCache
2010-06-12 15:35:28 122 Application_PostMapRequestHandler
2010-06-12 15:35:28 142 Application_EndRequest
2010-06-12 15:35:28 142 Application_PreSendRequestHeaders
2010-06-12 15:35:28 142 Application_PreSendRequestContent
2010-06-12 15:35:28 152 Application_BeginRequest
2010-06-12 15:35:28 152 Application_AuthenticateRequest
2010-06-12 15:35:28 162 Application_PostAuthenticateRequest
2010-06-12 15:35:28 162 Application_AuthorizeRequest
2010-06-12 15:35:28 162 Application_PostAuthorizeRequest
2010-06-12 15:35:28 172 Application_ResolveRequestCache
2010-06-12 15:35:28 172 Application_PostResolveRequestCache
2010-06-12 15:35:28 172 Application_PostMapRequestHandler
2010-06-12 15:35:28 172 Session_Start
2010-06-12 15:35:28 172 Application_AcquireRequestState
2010-06-12 15:35:28 182 Application_PostAcquireRequestState
2010-06-12 15:35:28 182 Application_PreRequestHandlerExecute
2010-06-12 15:35:28 192 Page_PreInit
2010-06-12 15:35:28 192 TestUserControl.Page_Init
2010-06-12 15:35:28 202 Page_Init
2010-06-12 15:35:28 202 TestUserControl.TestProperty.Set
2010-06-12 15:35:28 202 Page_InitComplete
2010-06-12 15:35:28 202 Page_PreLoad
2010-06-12 15:35:28 202 Page_Load
2010-06-12 15:35:28 202 TestUserControl.Page_Load
2010-06-12 15:35:28 202 TestUserControl.ShowData()
2010-06-12 15:35:28 212 TestUserControl.Repeater1.ItemDataBound()
2010-06-12 15:35:28 212 TestUserControl.Repeater1.ItemDataBound()
2010-06-12 15:35:28 212 TestUserControl.Repeater1.ItemDataBound()
2010-06-12 15:35:28 212 TestUserControl.Repeater1.ItemDataBound()
2010-06-12 15:35:28 212 TestUserControl.Repeater1.ItemDataBound()
2010-06-12 15:35:28 222 TestUserControl.Repeater1.ItemDataBound()
2010-06-12 15:35:28 222 TestUserControl.Repeater1.ItemDataBound()
2010-06-12 15:35:28 222 TestUserControl.Repeater1.ItemDataBound()
2010-06-12 15:35:28 222 TestUserControl.Repeater1.ItemDataBound()
2010-06-12 15:35:28 222 TestUserControl.Repeater1.ItemDataBound()
2010-06-12 15:35:28 232 TestUserControl.Repeater1.ItemDataBound()
2010-06-12 15:35:28 232 Page_LoadComplete
2010-06-12 15:35:28 232 Page_PreRender
2010-06-12 15:35:28 232 TestUserControl.Page_PreRender
2010-06-12 15:35:28 242 Page_SaveStateComplete
2010-06-12 15:35:28 242 TestUserControl.Page_Unload
2010-06-12 15:35:28 252 Page_Unload
2010-06-12 15:35:28 252 Application_PostRequestHandlerExecute
2010-06-12 15:35:28 252 Application_ReleaseRequestState
2010-06-12 15:35:28 252 Application_PostReleaseRequestState
2010-06-12 15:35:28 262 Application_UpdateRequestCache
2010-06-12 15:35:28 262 Application_PostUpdateRequestCache
2010-06-12 15:35:28 262 Application_EndRequest
2010-06-12 15:35:28 272 Application_PreSendRequestHeaders
2010-06-12 15:35:28 272 Application_PreSendRequestContent
2010-06-12 15:35:28 282 Application_BeginRequest
2010-06-12 15:35:28 292 Application_AuthenticateRequest
2010-06-12 15:35:28 292 Application_PostAuthenticateRequest
2010-06-12 15:35:28 302 Application_AuthorizeRequest
2010-06-12 15:35:28 302 Application_PostAuthorizeRequest
2010-06-12 15:35:28 302 Application_ResolveRequestCache
2010-06-12 15:35:28 312 Application_PostResolveRequestCache
2010-06-12 15:35:28 312 Application_PostMapRequestHandler
2010-06-12 15:35:28 322 Application_AcquireRequestState
2010-06-12 15:35:28 322 Application_PostAcquireRequestState
2010-06-12 15:35:28 322 Application_PreRequestHandlerExecute
2010-06-12 15:35:28 332 Application_PostRequestHandlerExecute
2010-06-12 15:35:28 332 Application_ReleaseRequestState
2010-06-12 15:35:28 332 Application_PostReleaseRequestState
2010-06-12 15:35:28 342 Application_UpdateRequestCache
2010-06-12 15:35:28 342 Application_PostUpdateRequestCache
2010-06-12 15:35:28 342 Application_EndRequest
2010-06-12 15:35:28 342 Application_PreSendRequestHeaders
2010-06-12 15:35:28 342 Application_PreSendRequestContent
2010-06-12 15:36:40 034 Session_End
您可能感兴趣的文章: