Asp. NET page cycles one of the learning notes

Source: Internet
Author: User

I. ASP. NET page life cycle Understanding-the key to the top priority

Asp. NET page life cycle--understanding: the top priority!!!
1. Basic concept: The so-called page life cycle, refers to an ASP-page class object from initialization to destruction through the step-by process;
2. Approximate steps:
(1) Initialization: Preinit,init,initcomplete
(2) Loading data and Pages: Loadstate,processpostdata,preload,load,processpostdata (second time) ...
(3) Trigger event: Changedevents postbackevent
(4) Save status and render page: Savestate,savestatecomplete,render
3. Detailed steps:
Processrequestmain->
Preinit-perfrompreinit () Pre-initialize: Prepare to initialize the page control, set the skin;
Init-initrecursive (NULL), page object initialization;
InitComplete (Oninitcomplete-eventargs.empty)-Page object initialization complete: Load ViewState, restore control state, register user-triggered events;
if (this. IsPostBack)
{
Loadstate-loadallstate (): Load Viewstate->processpostdata-processpostdata (this._requestvaluecollection,true) : Restore control state
}
->preload-onpreload (Eventargs.empty)->load-loadrecursive ()
if (this. IsPostBack)
{
Processpostdata Second try-processpostdata (this._leftoverpostdata,false)->raise Changedevents-raisechangedevents ()->raise postbackevent
-raisepostbackevent (this._requestvaluecollection);): Triggering control events
}
->savestatecomplete-onsavestatecomplete (eventargs.empty): Save page and control data to viewstate->
Render->rendercontrol (this. Createhtmltextwriter (this. response.output)): Generate final HTML code

Second, ProcessRequestMain () method to perform the step

1. Whether the IsPostBack property is true based on whether it contains _viewstate
2.LoadAllState () to load the value of the hidden field _viewstate into the ViewState property of the Page object
3. First call Processpostdata () to restore the property value of the server control contained in the property viewstate to the corresponding server control
4.Load the Page_Load method we use most often
5. Second call to Processpostdata ()
6.Raise changedevents is used to prepare the currently triggered events for server-side controls
7.Raise postbackevent perform events triggered by the previously flagged server-side controls
8.PreRender preparing to generate HTML code
9.SaveState put the last property of the control and the last user-defined value into ViewState [Generate hidden field]
10.Render Generating HTML code for the entire page

Third, the HttpApplication event processing process

Instances of the HttpApplication class are created in the ASP. NET infrastructure, not directly by the user. An instance of the HttpApplication class is used to process multiple requests during its lifetime, but it can only process one request at a time. This makes the member variable available for
Stores the data for each request.

The application executes the events handled by the module or user code defined in the Global.asax file in the following order:

1.BeginRequest starts processing the request (the first event in the pipeline chain as an HTTP execution when ASP. NET responds to a request)
2.AuthenticateRequest authorization verification succeeds, obtaining user authorization information (occurs when the security module has established a user ID. Note: The AuthenticateRequest event signaled that the configured authentication mechanism has authenticated the current request.
The subscribe to AuthenticateRequest event ensures that the request is authenticated before the attached module or event handler is processed. )
3.PostAuthenticateRequest Success (Note: This event is new in the. NET Framework version 2.0.) Occurs when the security module has established a user ID.
The Postauthenticaterequest event is raised after the AuthenticateRequest event occurs. The ability to subscribe to the Postauthenticaterequest event can access any data processed by Postauthenticaterequest. )
4.AuthorizeRequest authorization, typically used to check whether a user is granted permission (occurs when the security module has authenticated user authorization.) The AuthorizeRequest event signaled that the current request was authorized by ASP.
The AuthorizeRequest event is booked to ensure that the request is authenticated and authorized before the attached module or event handler is processed. )
5.PostAuthorizeRequest gets authorization (new events in. NET 2.0. Occurs when the currently requested user is authorized. The Postauthorizerequest event signaled that the current request was authorized by ASP.
The Postauthorizerequest event is booked to ensure that the request is authenticated and authorized before the attached module or handler is processed. )
6.ResolveRequestCache Gets the page cache result, which occurs when ASP. NET completes the authorization event so that the cache module serves the request from the cache, skipping the execution of an event handler, such as a page or XML Web services. )
7.PostResolveRequestCache Gets the cache (occurs when ASP. NET skips the execution of the current event handler and allows the cache module to satisfy requests from the cache.) ) After the Postresolverequestcache event,
Create an event handler (the page that corresponds to the request URL) before the Postmaprequesthandler event.
8.PostMapRequestHandler creates a Page object that occurs when ASP. NET has mapped the current request to the appropriate event handler. )
9.AcquireRequestState Get session *********** Note: Can be used to session******************* First, determine whether the current Page object implements the IRequiresSessionState interface,
If it is implemented, the SessionID is obtained from the request header of the browser, and the corresponding session object is obtained in the session pool of the server, and is finally assigned to the session property of the HttpContext context object.
10.PostAcquireRequestState Get session
11.PreRequestHandlerExecute prepares the execution of the Page object (execution event handler). )
* ProcessRequest method for executing page objects
12.PostRequestHandlerExecute finished the Page object *********** Note: Can be used to session*******************
13.ReleaseRequestState Release Request Status
14.PostReleaseRequestState the request state has been released (after the Postreleaserequeststate event, the response filter, if any) will filter the output. )
15.UpdateRequestCache Update Cache
16.PostUpdateRequestCache Cache has been updated
17.LogRequest Log Records
18.PostLogRequest completed Log
19.EndRequest Complete Request

Asp. NET page cycles one of the learning notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.