A Web Forms application can't be migrated to modern .NET in the way an MVC application can, because Web Forms was never carried over. The pages have to be rebuilt. For most applications the right route is to rebuild the pages a few at a time in ASP.NET Core, with the old and new applications running side by side behind one address. Rebuilding in one go suits applications small enough to test completely before the switch, and replacing the application makes sense when a packaged product now does the same job.
Is ASP.NET Web Forms still supported?
Yes. Web Forms is part of .NET Framework, and .NET Framework 4.8 is supported as a component of Windows for as long as the Windows version it runs on is supported. It gets security and reliability fixes. It gets no new features, and it isn't part of modern .NET.
So there is no fixed deadline, as long as the Windows version it runs on is still supported and patched. What changes over time is everything around the application:
- Newer versions of the libraries it uses drop .NET Framework support.
- Third-party control suites may not keep up. Check the support status of each one the application uses.
- It can only be hosted on Windows with IIS.
- Maintaining it safely needs people who understand the page lifecycle, ViewState and postbacks.
What are the options for modernising a Web Forms application?
There are four, and they aren't exclusive. Many applications end up with a mix.
Keep it and stabilise it
Leave the application on .NET Framework 4.8 and reduce the risk of running it: source control, a repeatable deployment, patched servers, monitoring, and tests around the parts that change. This suits an internal application that works, changes a few times a year and has a limited life ahead of it.
Rebuild it page by page in ASP.NET Core
A new ASP.NET Core application sits in front of the old one and takes over pages in groups. Users see one site throughout. This is the route for most business applications that still matter and still change.
Rebuild it in one go
Write the replacement, test it, switch over. It works for small applications that can be tested end to end before the switch. On anything larger it carries the risks of a big-bang rewrite, which we cover in Rebuild or modernise?.
Replace it with a product
If the application is a home-grown CRM, helpdesk or holiday-booking system, a packaged or SaaS product may now do the job. You swap a rebuild for a data migration and a set of integrations with the systems around it, so count those before deciding.
Why can't Web Forms be converted automatically?
Web Forms hides the web. A page is built from server controls that remember their state between requests in ViewState, and a button click posts the whole form back to the server and raises an event in the code-behind file. ASP.NET Core has no ViewState, no postback events and no server controls, so the following have no direct equivalent:
GridView,Repeater,FormViewand the other data controls.UpdatePaneland the rest of ASP.NET AJAX.- Data source controls:
SqlDataSource, which can hold SQL in the page markup, andObjectDataSource, which calls methods on a business object. - Third-party grids, schedulers and report viewers built for Web Forms.
Some parts do map across. Master pages become layouts. User controls become partial views, view components or Blazor components. HTTP modules and handlers become middleware. Membership is replaced by ASP.NET Core Identity or an external identity provider, and forms authentication by cookie authentication. Check early whether existing passwords will still work or users will need to reset them.
Migration tools can help rewrite pages, but someone who understands what each page does has to review and test the result.
Razor Pages, MVC or Blazor: which should replace Web Forms?
All three are part of ASP.NET Core, and one application can use more than one.
Razor Pages is the closest in shape. Each URL has a page and a class behind it that handles the request, which is how most Web Forms teams already think. It suits forms-over-data applications: search screens, edit screens, lists and reports.
MVC suits applications with a lot of shared behaviour across screens, or teams that already use MVC elsewhere. Both can build the same kinds of application, so choose whichever way of organising the code, by controller or by page, fits the application and your team's other code.
Blazor uses components with event handlers, which feels familiar after Web Forms: a button has a click handler and the screen updates without a full page load. It suits highly interactive screens, such as a planning board or a grid with inline editing. With interactive server rendering, each open browser tab holds a connection to the server and its state lives in server memory, which affects how you scale and what happens when a connection drops.
For a typical line-of-business application we would start with Razor Pages and use Blazor components for the few screens that need them.
How do you migrate Web Forms to ASP.NET Core page by page?
The incremental approach uses a reverse proxy. Microsoft's YARP library runs inside the new ASP.NET Core application, which receives every request. If it has a page for that URL, it serves it. If not, it forwards the request to the Web Forms application, which carries on as before.
Two things make this workable:
- Microsoft's System.Web adapters let the new application use the old one's sign-in and session state, so users stay signed in across both. Test this early. Windows authentication needs a separate plan, because the adapters can't pass Windows identities across.
- Shared class libraries that target .NET Standard 2.0 can be used by both applications, so business rules exist once.
Move pages in groups that make sense to users, such as everything to do with customer accounts, so nobody bounces between old and new styling mid-task. Start with a small, low-risk area to prove the proxy, sign-in, session handling, deployment and rollback. After that, take areas in order of business value, dependencies and risk. Switch the old application off only when every page, web service, background job and sign-in dependency has moved or been deliberately retired.
If both applications share a database during the move, keep schema changes compatible with both until the old one has gone.
How do you prepare a Web Forms application for migration?
The biggest factor in the effort is where the logic lives. A page whose code-behind validates input, applies pricing rules, runs SQL and formats the result has to be understood line by line. A page that calls a service class and binds the result is mostly a UI job.
While still on .NET Framework:
- Move business rules and data access out of code-behind files into class libraries.
- Replace
SqlDataSourcecontrols with calls to those libraries. - Stop using
HttpContext.CurrentandSessionoutside the web layer. Pass values in. - Retarget the libraries to .NET Standard 2.0 where their dependencies allow.
- Add tests around the extracted logic.
- List what is kept in session and ViewState, and how large it is.
This is worth doing even if the rebuild is a year away, and the same libraries then serve the new pages.
What makes a Web Forms migration harder than it looks?
- Large objects in session state, especially ones that can't be serialised.
- Pages that depend on ViewState to carry data between postbacks.
- A third-party control suite used on every screen, with behaviour users rely on.
- Reports built with a server-side report viewer control.
- ASMX web services in the same application that other systems call.
- Windows authentication and Active Directory group checks scattered through the pages.
- No tests, and nobody left who knows why a page behaves as it does.
None of these stops a migration. Each one is a piece of work to size before anyone commits to a date.
Should you migrate or replace a Web Forms application?
- Keep and stabilise it if it works, rarely changes and is due to be retired.
- Rebuild it page by page if it holds business rules you still depend on and it changes regularly.
- Rebuild it in one go only if it is small enough to test completely before switching.
- Replace it with a product if what it does is no longer specific to your business.
Our guide to upgrading .NET Framework to modern .NET covers the rest of the solution: the libraries, services and jobs that sit behind the pages.
We rebuild Web Forms applications in stages on modern .NET, alongside your team or on your behalf, and keep the systems connected to them working throughout. Read more about our legacy modernisation service.
Email [email protected] with your brief.