A WebForms page remembers things. It remembers which row was selected, which panel was open, what the price was when the user loaded the page. Much of that memory lives in ViewState, a hidden field the framework writes and reads for you. Nobody designed it as a data store. It became one anyway.
This note covers how to find out what your pages keep in ViewState before you move them. It is a measurement exercise. You do not need to read every code-behind file.
Why it matters for the migration
Blazor and Razor Pages do not have ViewState. When you rebuild a slice, anything that depended on it has to go somewhere deliberate. If you skip this step, the new page passes a visual check and then fails on the third click of a real workflow.
The usual symptoms in a rewrite: a discount applies twice, an edit form saves the wrong record after a back-button visit, a wizard loses step two. Each one is state that used to ride along in the hidden field.
Step 1: Measure size per page
Start with numbers. Capture the __VIEWSTATE field length for each page in your highest-traffic workflows. The simplest route is to replay recorded requests through your harness and log the field length from each response.
- Pages with a small field, a few hundred characters, are mostly framework bookkeeping.
- Pages with a field in the tens of kilobytes are holding data. Read those first.
Rank pages by size times traffic. That list is your reading order.
Step 2: Decode the largest ones
ViewState is Base64 of a serialized object graph. If ViewStateEncryptionMode is off and MAC is the only protection, you can decode it with a small console tool that uses LosFormatter on a .NET Framework target. If it is encrypted, run the decode inside the app, behind a debug-only handler, against a test copy. Do not do this on production.
Write out what you find as a table per page: key, type, who sets it, who reads it.
Step 3: Classify each entry
In our experience every entry falls into one of four groups.
- Control state. Selected index, expanded node, sort direction. Blazor component fields hold this. Low risk.
- Cached query results. A grid's data source stored so the page does not hit the database on postback. Replace with a fresh query or a short-lived cache. Check that the old behavior was not masking a slow query.
- Values read back on save. An original price, a row version, a record ID. These are the dangerous ones. They are often used as a hand-rolled concurrency check, or as a trust boundary the server never re-verified. Move them to the server side and validate there.
- Workflow position. Wizard step, completed sections. Make this explicit: a database row, a session entry, or a route parameter.
Group 3 deserves a characterization test each. Record the old behavior with a stale value and with a tampered one, and pin what the old page does.
Step 4: Watch for the other hidden carriers
ViewState is not the only place. Check for:
Sessionkeys set inPage_Loadand read on a later page.Page.ItemsandCacheused as scratch space.- UpdatePanel partial postbacks that rely on state from the full-page load.
- Hidden fields and query strings set by client script.
The session case has its own constraints when old and new apps run side by side. We cover that in the note on sharing session state with your first .NET 8 slice.
Step 5: Decide per page, then write it down
For each page in the first slice, record where each group 2, 3 and 4 entry will live in the new code. Put that in the slice plan next to the routing and data notes. A reviewer should be able to see that no ViewState key is unaccounted for.
What we will not do
We do not try to emulate ViewState in the new stack. Compatibility shims that serialize page state into a hidden field bring the old problems along, and they make the new code harder to test. Name the state, then put it somewhere it can be tested.
Where AI helps and where it does not
A coding agent is useful for the bulk reading: listing every ViewState["..."] access, grouping them by page, and drafting the key table. It cannot tell you which keys are business contracts. A senior engineer reviews the group 3 list, and the harness proves the result.
What you should have at the end
- A ranked list of pages by ViewState size and traffic.
- A key table for each page in the first slice.
- A characterization test for every value read back on save.
- A decision for each entry on where it goes in .NET 8.
That is a day or two of work for a handful of pages, and it removes a category of surprise from the estimate.