📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

You own a large ASP.NET Web Forms application that the business still depends on. How would you migrate it to modern .NET? Compare Razor Pages, Blazor and a JavaScript SPA as targets, explain what makes Web Forms hard to migrate, and how you would move it page by page without a big-bang rewrite.

Covers Web Forms migration: why there is no automated path (ViewState, server controls, page lifecycle, code-behind business logic), comparing Razor Pages, Blazor (Server/WebAssembly/Auto) and an SPA, extracting logic first, page-by-page migration behind YARP with shared auth and session, and how to choose.

Senior Theory Advanced blazor legacy-migration razor-pages strangler-fig web-forms yarp

🎯 Key points

  • No automated conversion: server controls, ViewState, postbacks and the page lifecycle have no direct equivalent
  • First extract business logic from code-behind into tested services shared by old and new UI (characterisation tests pin behaviour)
  • Blazor is closest in mental model (components, events, server-side state); Razor Pages is simplest for form-and-page apps; SPA needs a team and an API
  • Page-by-page: new ASP.NET Core app with YARP forwarding unmigrated URLs to Web Forms, which keeps working until the last page moves
  • Share authentication (System.Web adapters remote auth or shared cookie) and session (remote session or a distributed store); redirect old .aspx URLs
  • Treat UX as a requirement: keep workflows familiar, involve key users, pilot pages with a feature flag, and measure page load and task time
  • Test every migrated page: characterisation, end-to-end (Playwright) and accessibility checks before switching its route
  • Third-party control suites (Telerik, DevExpress) and UpdatePanel usage drive most of the cost

⏱ 30-second answer

Web Forms has no automated migration path: server controls, ViewState, postbacks and the page lifecycle don't exist in ASP.NET Core, and business logic usually lives in code-behind. So the plan is: extract the logic first into tested services both UIs can use, then migrate page by page behind YARP, sharing authentication and session, while the Web Forms app keeps serving every page not yet moved.

For the target: Blazor is the closest mental model and suits internal line-of-business apps; Razor Pages is the simplest for form-and-page apps; an SPA fits when a separate front-end team justifies a new API layer. Users should barely notice the move except that pages get faster (losing ViewState often halves load times), so pilot pages with key users and test each one end to end. The trade-off: Blazor feels familiar but ties the UI to .NET; an SPA is more flexible but roughly doubles what you build and test.

🗣 Full answer (senior)

How I would answer this in an interview

"First I'd be honest about why Web Forms is the hardest legacy migration. There's no tool that converts it, because its core ideas don't exist in ASP.NET Core: server controls that render their own HTML, ViewState carrying control state in a hidden field, postbacks that replay the page lifecycle, and UpdatePanel partial refreshes. The bigger problem is usually that the business rules live in Button1_Click handlers in code-behind. So the first step isn't choosing a framework, it's pulling business logic out of code-behind into services with tests, which both the old pages and the new UI can call.

For the target, I'd choose per app. Blazor is the closest mental model: components, event handlers and state that lives on the server, so Web Forms developers pick it up quickly; for an internal app, Blazor with interactive server rendering is a strong fit. Razor Pages is the simplest when pages are mostly forms and lists: one page, one handler, plain HTML. An SPA in React or Angular makes sense when there's a dedicated front-end team or very rich client behaviour, but it means designing and securing an API too. For example, at [company] we [moved an internal Web Forms app of about N pages to Blazor, page by page, over M months]; [result].

The migration itself runs page by page. A new ASP.NET Core app sits in front with YARP; any URL not yet migrated is forwarded to the Web Forms app. Authentication is shared with System.Web adapters or a shared cookie, and session either goes remote or moves to a distributed store. The mistake I see is a two-year rewrite that the business cancels at month fourteen. Shipping a migrated page every sprint keeps the funding."


Why Web Forms is hard to migrate

Web Forms concept Why it doesn't carry over What replaces it
Server controls (GridView, asp:TextBox) Render their own HTML and state Razor markup, Blazor components, tag helpers
ViewState Hidden field with serialised control state Explicit model binding, component state
Postback + page lifecycle Page_Load, Page_PreRender, event replay Request handlers / component lifecycle
UpdatePanel Partial postbacks via ASP.NET AJAX Blazor interactivity, htmx, SPA calls
Code-behind business logic Tied to the page class Application services, MediatR handlers
Third-party control suites Web Forms-only versions Vendor's Blazor or JS suite (new licence)

Choosing the target

Target Fits Costs Avoid when
Blazor (Server / Auto) Internal LOB apps, .NET team, many interactive forms Server: a SignalR circuit per user; WebAssembly: download size Public high-traffic sites with SEO needs (use static SSR)
Razor Pages Form-and-page CRUD, SEO, simple hosting Less interactivity without JS Highly interactive dashboards
SPA + API Separate front-end team, rich client, mobile reuse Two codebases, API security, more tests Small team of .NET developers only

Production example

An internal case-management system had 140 Web Forms pages. Extracting logic took two months; then 8–12 pages a sprint moved to Blazor behind YARP. After nine months the Web Forms app served under 2% of requests and was retired the next quarter; page load time on migrated screens dropped from 2.8 s to 0.9 s, largely because ViewState (up to 400 KB on some pages) went away.

🔍 What the interviewer is checking

Checks that the candidate understands why Web Forms is uniquely hard to migrate and can run a realistic incremental migration with a sensible choice of target.

Green flags

  • Explains ViewState, server controls and code-behind as the real obstacles
  • Extracts business logic before porting UI
  • Compares Blazor, Razor Pages and SPA with honest trade-offs
  • Page-by-page plan with YARP, shared auth and session, and URL redirects

Red flags

  • Expects a conversion tool to do it
  • Proposes a big-bang rewrite
  • Picks a target by fashion rather than by team and app

📚 Learn in depth

1. How Web Forms actually works

A Web Forms page is a class that builds a control tree on every request. On a postback, the browser posts the whole form, including __VIEWSTATE and __EVENTTARGET, and the page replays its lifecycle to rebuild state and raise the right event.

GET  /Orders.aspx  -> Init -> Load -> PreRender -> SaveViewState -> Render (HTML + __VIEWSTATE)
POST /Orders.aspx  -> Init -> LoadViewState -> LoadPostData -> Load
                   -> RaisePostBackEvent (Button1_Click) -> PreRender -> SaveViewState -> Render

That model hides HTTP from the developer, which is why teams loved it and why it can't be translated mechanically: modern frameworks expose HTTP or component state explicitly.

2. Step zero: extract the logic

Code-behind often mixes data access, validation and rules:

Orders.aspx.cs
  btnApprove_Click -> SQL update + email + audit + UI change

Refactor it into an application service (IOrderApprovalService.ApproveAsync) in a class library that multi-targets net48;net10.0. Web Forms calls it today; Blazor or Razor Pages calls it tomorrow. Characterisation tests pin the behaviour before you move it.

3. The incremental topology

Browser
   |
 ASP.NET Core 10 app (YARP + new pages)
   |-- /orders/*      -> new Blazor/Razor pages
   |-- /reports/*     -> new pages
   '-- /{**catch-all} -> YARP -> Web Forms app on IIS (.NET Framework 4.8)

Shared: authentication (remote auth or shared cookie), session (remote or Redis), database

URLs often change (/Orders.aspx?id=5 to /orders/5); add redirects in the new app so bookmarks keep working.

4. Sharing auth and session

  • System.Web adapters (Microsoft.AspNetCore.SystemWebAdapters): remote authentication lets the new app ask the old app who the user is; remote session lets it read and write the old app's session through an endpoint (session values must be serialisable with registered key serialisers).
  • Shared cookie: both apps use the same cookie name and Data Protection keys (the old app via Microsoft.Owin.Security.Interop), so either can sign the user in.
  • Moving session to a distributed store first (SQL Server or Redis session state on Web Forms) simplifies later steps.

5. Blazor render modes for Web Forms refugees

.NET 8+ Blazor Web Apps choose per component: static SSR (plain HTML, like Razor Pages), Interactive Server (events over a SignalR circuit, state on the server: closest to Web Forms), Interactive WebAssembly (runs in the browser), or Auto. Interactive Server costs memory per connected user (often tens to hundreds of KB per circuit) and needs sticky sessions or Azure SignalR Service when scaled out.

6. Ordering the work

Score pages by business value, change frequency and risk. Migrate a low-risk, high-traffic page first to prove the topology, then the pages that change most often (so new features are built once, in the new stack). Leave rarely used admin pages until last; some can simply be deleted.

Try it yourself

  1. Open a Web Forms page in the browser dev tools and measure the size of __VIEWSTATE.
  2. Extract one Click handler into a service with a characterisation test, called from the page.
  3. Build the same screen in Razor Pages and in Blazor Interactive Server; compare code size and payload.
  4. Put YARP in a new ASP.NET Core app with a catch-all route to the Web Forms app, and move one page.
  5. Configure System.Web adapters remote authentication and confirm the new page sees the same user.

💻 Code

Before: a Web Forms page with logic in code-behind.

// BEFORE: Orders.aspx.cs (.NET Framework 4.8)
public partial class Orders : System.Web.UI.Page
{
    protected void btnApprove_Click(object sender, EventArgs e)
    {
        var id = int.Parse(hfOrderId.Value);
        using var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Main"].ConnectionString);
        conn.Open();
        new SqlCommand($"UPDATE Orders SET Status='Approved' WHERE Id={id}", conn).ExecuteNonQuery(); // SQL injection
        lblMessage.Text = "Approved";
        gvOrders.DataBind();
    }
}

Step 1: extract the rule into a service both UIs can call.

namespace Contoso.Orders.Application;

public interface IOrderApprovalService
{
    Task

⚠ Common mistakes

  • Mistake: Planning a big-bang rewrite of the whole Web Forms app. Why it is wrong: years with no visible value, frozen features and a high chance of cancellation. Instead: migrate page by page behind YARP and ship every sprint.
  • Mistake: Porting pages before extracting business logic. Why it is wrong: rules get rewritten (and changed) in the new UI. Instead: move logic into tested services first, shared by both UIs.
  • Mistake: Choosing Blazor Server for a public, high-traffic site. Why it is wrong: each user holds a SignalR circuit and server memory. Instead: use static SSR or Razor Pages for public pages and interactive modes only where needed.
  • Mistake: Choosing an SPA for a team of .NET-only developers. Why it is wrong: a second stack, API security and build pipeline with no one to own them. Instead: pick the target your team can sustain.
  • Mistake: Ignoring third-party control suites. Why it is wrong: Telerik/DevExpress Web Forms controls have no drop-in equivalent and drive much of the cost and licence change. Instead: inventory them during analysis and price their replacements.
  • Mistake: Breaking old URLs. Why it is wrong: bookmarks, emails and integrations point at .aspx pages. Instead: add permanent redirects in the new app.
  • Mistake: Two separate logins during the transition. Why it is wrong: users bounce between apps and must sign in twice. Instead: share authentication through System.Web adapters or a shared cookie from day one.

🏛 Senior insight: trade-offs

Web Forms migrations fail on funding, not technology. The page-by-page approach matters because it turns a long project into a stream of visible improvements; I report progress as the percentage of requests served by the new app, which the business understands. I'm also willing to leave the Web Forms app alone if it is stable and rarely changed: .NET Framework 4.8.1 is supported as part of Windows, and the money may be better spent elsewhere.

On the target, choose for the team that will maintain it. Blazor's familiarity with Web Forms developers is a real advantage, not a soft one.

Strategy When it fits Cost When not to
Page by page behind YARP Large, actively changed app Proxy, shared auth, two apps for a while Tiny app: rewrite directly
Extract logic, keep Web Forms UI Stable UI, logic needs reuse Low UI itself is the problem
Leave as is on 4.8.1 Stable, rarely changed, retiring Rising skills and hosting risk Needs new features often
Full rewrite Small app or radically new requirements High risk, frozen features Business-critical with weak specs

🔗 Follow-ups the interviewer may ask

  1. When: Candidate is vague on how ViewState or postbacks work Why: Checks the fundamentals of Web Forms itself
    How to answer

    Web Forms (2002) made web development feel like Windows Forms: drag server controls onto a page, double-click a button, write a Click handler in code-behind. It hides HTTP's statelessness with two tricks: postbacks (interactions POST the form back to the same page) and ViewState (a hidden field, signed by default and optionally encrypted, that carries control state between requests). Each request runs the page lifecycle: Init, Load, the postback event, PreRender, Render. UpdatePanel can make a postback update only part of the page, but the server still runs the whole lifecycle.

    It is productive for forms-over-data apps, but pages get heavy, logic hides in code-behind and it is hard to test. It is built on System.Web, so it never came to modern .NET. Blazor is the closest in feel, Razor Pages the closest in structure, an SPA plus API another option. The trade-off: no tool converts it automatically; migration is page by page.

  2. When: Candidate mentions session state during the migration Why: Checks they can move session to a store both apps can share
    How to answer

    In-process session lives in the w3wp.exe memory, so users are pinned to one server (sticky sessions) and lose state on every app pool recycle. Switch <sessionState mode="SQLServer"> or a Redis provider (for example Azure Cache for Redis) so session survives recycles and works across servers, which improves availability and lets you scale out. This forces session objects to be serialisable and adds a store round trip per request, which flushes out large or non-serialisable objects: measure session size and trim it. It also prepares the migration: ASP.NET Core has no in-process Session by default, its session sits on IDistributedCache, and the System.Web adapters' remote session lets a new ASP.NET Core app read the legacy app's session during an incremental, page-by-page move so users don't notice the switch.

  3. When: Candidate describes the strangler fig and YARP topology Why: Checks how they plan the overall incremental migration of a large monolith
    How to answer

    I wouldn't rewrite it. I'd use the strangler fig pattern: put a new ASP.NET Core 10 app in front, with YARP proxying every route it doesn't handle yet to the old .NET Framework 4.8 app. Then I move features route by route, starting with slices that are valuable and loosely coupled, while the team keeps shipping.

    The tricky parts are shared state: I use System.Web adapters to share authentication and session between the two apps, multi-target shared libraries to .NET Standard 2.0, and keep one database until the code has moved, so I'm never migrating code and data in the same step.

    I measure progress by the percentage of traffic served by the new app, legacy code deleted, and error rate and p95 per migrated route, with a flag to send a route back.

    The trade-off: running two apps for a while costs effort, but every step is small and reversible.

🛠 Real-world problems: how you handle them

Web Forms page migration stalls on a 400 KB ViewState grid
Situation
An internal [case-management] Web Forms app with [about 140 pages] used by [600 staff across Australia]. The team was migrating to Blazor page by page behind YARP.
Signals
The most-used page (case search with a third-party grid) loaded in [2.8 s]; users complained of slowness on [regional connections]. Browser dev tools showed `__VIEWSTATE` of [about 400 KB]. The migration team had skipped the page as 'too hard'.
Investigation
Inventoried the grid's features actually used (sorting, paging, filters, export), measured payloads in dev tools and Application Insights page views, and found the grid bound the full result set into ViewState. Characterisation tests captured the search behaviour from the existing code-behind.
Resolution
Immediate: disabled ViewState on the grid and moved to server-side paging in the Web Forms page, cutting load time to [1.4 s]. Real fix: extracted the search logic to a service and built the page in Blazor with server-side paging; routed `/cases/search` to the new app in YARP.
Prevention
Page-size budget in the migration checklist; Application Insights alert on page load p95; characterisation tests kept as regression tests for the new page.

How to tell it (STAR)

**S:** We were moving [an internal case-management Web Forms app] to Blazor one page at a time. **T:** The busiest page was slow and the team had avoided migrating it, so I took it on. **A:** I measured it: [400 KB] of ViewState from a grid holding the whole result set. As a quick win I disabled ViewState and added server-side paging in Web Forms. Then I extracted the search logic into a tested service and rebuilt the page in Blazor, routed through YARP. **R:** Load time went from [2.8 s] to [0.9 s], and once the hardest page was done the team's pace picked up to [10 pages a sprint].

More in Migration Topics

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me