asp.net page life cycle and viewstate

22
Page Life Cycle And ViewState Presenter: Vijay Goyal, Mindfire Solutions Skype: mfsi_vijayg Date: 30/09/2013

Upload: mindfire-solutions

Post on 06-May-2015

5.570 views

Category:

Technology


0 download

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 1: ASP.NET Page life cycle and ViewState

Page Life Cycle And ViewState

Presenter: Vijay Goyal, Mindfire SolutionsSkype: mfsi_vijaygDate: 30/09/2013

Page 2: ASP.NET Page life cycle and ViewState

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

Page 3: ASP.NET Page life cycle and ViewState

This is not an IIS course

Conferrer: Vijay Goyal, Mindfire Solutions

Page 4: ASP.NET Page life cycle and ViewState

The Two Important Services

Conferrer: Vijay Goyal, Mindfire Solutions

Page 5: ASP.NET Page life cycle and ViewState

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.

Page 6: ASP.NET Page life cycle and ViewState

The Page Life Cycle Begins..

Conferrer: Vijay Goyal, Mindfire Solutions

Page 7: ASP.NET Page life cycle and ViewState

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

Page 8: ASP.NET Page life cycle and ViewState

Formation Of Control Heirarchy

Conferrer: Vijay Goyal, Mindfire Solutions

Page 9: ASP.NET Page life cycle and ViewState

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

Page 10: ASP.NET Page life cycle and ViewState

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()

Page 11: ASP.NET Page life cycle and ViewState

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.

Page 12: ASP.NET Page life cycle and ViewState

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 13: ASP.NET Page life cycle and ViewState

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

Page 14: ASP.NET Page life cycle and ViewState

A Scenario

Conferrer: Vijay Goyal, Mindfire Solutions

Page 15: ASP.NET Page life cycle and ViewState

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

Page 16: ASP.NET Page life cycle and ViewState

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

Page 17: ASP.NET Page life cycle and ViewState

Security??- ViewState Decoder (a nice tool created by Fritz Onion).

- EnableViewStateMac

- ViewStateEncryptionMode (Always/Auto , control calls Page.RegisterRequiresViewStateEncryption() /Never)

Conferrer: Vijay Goyal, Mindfire Solutions

Page 18: ASP.NET Page life cycle and ViewState

Prevent Tampering

Conferrer: Vijay Goyal, Mindfire Solutions

Page 19: ASP.NET Page life cycle and ViewState

Prevent Tampering

Conferrer: Vijay Goyal, Mindfire Solutions

Page 20: ASP.NET Page life cycle and ViewState

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

Page 21: ASP.NET Page life cycle and ViewState

Conferrer: Vijay Goyal, Mindfire Solutions

Page 22: ASP.NET Page life cycle and ViewState

Presenter: Vijay Goyal, Mindfire Solutions