asp.net page life cycle and viewstate
DESCRIPTION
This session is a brief on the pre page life cycle events(Just a quick route map), the Page life cycle events, how is Viewstate important to page life cycle events & Life without Viewstate.TRANSCRIPT
Page Life Cycle And ViewState
Presenter: Vijay Goyal, Mindfire SolutionsSkype: mfsi_vijaygDate: 30/09/2013
Conferrer: Vijay Goyal, Mindfire Solutions
Agenda Of The Seminar
- Pre Page Life Cyle (Asp.Net Inside IIS)- What on Earth is ViewState?- The different (Important) stages of Life Cycle- Where ViewState comes into the picture?- Dynamically created control- Deal with the burden of ViewState on the page - Some Demo...with some more Demo
This is not an IIS course
Conferrer: Vijay Goyal, Mindfire Solutions
The Two Important Services
Conferrer: Vijay Goyal, Mindfire Solutions
The ProcessRequest()- After all the registered Modules are executed. The page is ready to be served.
- For this IIS uses the handler's mapping, to map the request to the appropriate handler.
- ProcessRequest() method is executed and Page Life Cycle begins
Conferrer: Vijay Goyal, Mindfire Solutions.
The Page Life Cycle Begins..
Conferrer: Vijay Goyal, Mindfire Solutions
Formation Of Control Heirarchy
- Request to an aspx page is served by a compiled class“C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files”
- Initializes the page's control hierarchy
Conferrer: Vijay Goyal, Mindfire Solutions
Formation Of Control Heirarchy
Conferrer: Vijay Goyal, Mindfire Solutions
But What's ViewState??
- Its a misunderstood topic- An object of Statebag class- Stores changes done programatically- SelectedIndex / PageIndex not stored- A property of System.Web.UI.Controls- A key/value pair indexer.- Serialized to _VIEWSTATE hidden field- ViewState is a hungry beast.
Conferrer: Vijay Goyal, Mindfire Solutions
Initialization
Conferrer: Vijay Goyal, Mindfire Solutions.
- PreInit (Entry point, Non Recursive)
- Init (Tracking of Viewstate is not enabled
/ Enabled for child controls, Recursive)
- InitComplete (Viewstate tracking is turned on, Non Recursive)
- SaveViewState()
- Page.TrackViewState()
Load ViewState/Page Data
- Invoked only on Postbacks
- LoadControlState (Introduced in Asp.Net 2.0,gridview page control, SaveControlState()l)
- LoadViewState (Page and controls restored,SaveViewState())
- LoadPostData (Controls implement IpostBackDataHandler,Selected value in dropdown, checkbox, Textbox)
Conferrer: Vijay Goyal, Mindfire Solutions.
Loading the Page...
Conferrer: Vijay Goyal, Mindfire Solutions
- PreLoad (Non Recursive, End of Viewstate data load)
- Load (Top down approach, Previous State is fully loaded)
- RaisePostDataChangeEvent (Controls implement IpostBackDataHandler, TextChanged/SelectedIndexChanged)
- RaisePostBackEvent (Controls implement IpostBackDataHandler,click event)
- LoadComplete (Page only)
Page Rendering- PreRender (Recursive, Last update before the page is rendered)
- PreRenderComplete (last event before the page's view state is saved.)
- SaveControlState
- SaveViewState (Control/Viewstate data are serialized to _VIEWSTATE)
- Render and Unload (Renders the html to Client, Final Cleanup,closing db, finishing up logging..etc)
Conferrer: Vijay Goyal, Mindfire Solutions
A Scenario
Conferrer: Vijay Goyal, Mindfire Solutions
Dynamically Added Controls
- They are not part of the compiled class
- Should be added in every page execution
- Plays catchup (go thru all the page life cycle events of their own, Before Page Render)
- Recommended to call in PreInit or Init, before tracking is enabled
Conferrer: Vijay Goyal, Mindfire Solutions
Abbreviating ViewState
- Disable ViewState
- System.Web.UI.LosFormatter (Limited Object Serialization)
- Compress/Decompress (SavePageStateToPersistenceMedium, LoadPageStateFromPersistenceMedium)
- Store in an external file (Use SessionId/ GUID)
- Others... (Flesk.ViewStateOptimizer)
Conferrer: Vijay Goyal, Mindfire Solutions
Security??- ViewState Decoder (a nice tool created by Fritz Onion).
- EnableViewStateMac
- ViewStateEncryptionMode (Always/Auto , control calls Page.RegisterRequiresViewStateEncryption() /Never)
Conferrer: Vijay Goyal, Mindfire Solutions
Prevent Tampering
Conferrer: Vijay Goyal, Mindfire Solutions
Prevent Tampering
Conferrer: Vijay Goyal, Mindfire Solutions
Here and there...
Conferrer: Vijay Goyal, Mindfire Solutions
Machine.Config file - <machineKey validation="SHA1" validationKey="F3690E7A3143C185AB1089616A8B4D81FD55DD7A69EEAA3B32A6AE813ECEECD28DEA66A23BEE42193729BD48595EBAFE2C2E765BE77E006330BC3B1392D7C73F" DecryptionKey =” ” />
- Local Security Authority Subsystem Service component
- References http://msdn.microsoft.com/en-us/library/ff649308.aspxhttp://msdn.microsoft.com/en-us/library/ms178472.aspxhttp://pluralsight.com
Conferrer: Vijay Goyal, Mindfire Solutions
Presenter: Vijay Goyal, Mindfire Solutions