Strangling Web Forms in 2026
I started writing this post in December 2017. It got to about six and a half thousand words, stopped
mid-sentence, and sat in a drafts folder for the best part of nine years. In fairness to past me,
the half that was a step-by-step guide rotted long before I’d have finished it; it involved
submoduling the dev branch of an unpublished Microsoft repository, which tells you everything you
need to know.
The other half didn’t rot at all. And as it turns out, the problem it was about hasn’t gone anywhere either.
Web Forms never came to .NET Core. It still ships in .NET Framework 4.8.1, it’s supported for as long as the version of Windows it’s sat on, and an awful lot of it is still quietly taking orders, booking appointments and printing invoices. If you’re on .NET Framework 4.6.2, support for that ends on 12 January 2027, so for some of you this has stopped being a “one day” conversation.
So, how do you get off it without betting the company?
Estate
Whenever I’ve inherited heritage software, my first job has never been the migration itself. It’s establishing the estate: what the software actually does.
Most legacy code I’ve worked on was being maintained by developers who weren’t around for its whole history. The original authors are long gone, and what’s left is speculation and grey areas. But your number one job is still to understand the functionality of the suite.
Not how it works. And as amusing or aggravating as the why-it-works-that-way might be, that isn’t important yet either.
Yet. Because if I’m honest, the why is my favourite part of legacy work. Reverse engineering the decisions behind a codebase is half exploring the map in an adventure game, poking into every dark corner to see what’s there, and half getting inside your opponent’s head in a PvP match: work out what they were thinking and you can predict where the next surprise is hiding before it finds you. Get good at it, and the estate stops being a minefield and starts being a puzzle.
Tact
Those that know me well probably wouldn’t use the word “tact” in the same sentence as my name. Bad code really gripes me, and my mouth has a habit of moving before my brain catches up. That never helped anyone, so I’ve had to set myself a couple of ground rules:
- Presume the bizarre and downright crazy code you come across was driven by a reason you simply can’t see, and that not seeing it is your shortcoming.
- Accept that decisions were made under constraints you can’t fathom, and that complaining about it changes precisely nothing.
Every estate has its lore, and the quickest way to learn it is from the people who already know it. They’ll tell you about the outage that explains that odd retry loop, or the customer whose contract is the reason a feature can never be switched off. Ask questions, starting from the high-level design and digging down where you need to, and make a real effort not to point fingers. If the people answering don’t know how bad (I think) their code is, I’d much rather show them by example later on than shame them now.
Mining
Alongside the people, or in their absence, I dig through code. The first thing I look for is an up to date and comprehensive test suite… one day that might even pan out for me. Most of the time there’s no test project at all. On a good day there’s one, full of empty, redundant and commented-out blocks.
Without tests, I start from the public surface area. What does the customer actually touch? What are the common interactions? What services, API calls and database logic do the most common journeys need?
Don’t try to memorise and diagram everything. Take notes, correct any documentation you prove wrong, and get a feel for how the thing hangs together. In 2026 I’d add one thing to this: a list of every route the application serves, because that list becomes your migration plan later on. Web server logs will give you the routes that are actually hit, which is not always the same list as the routes that exist.
Goal
You might think the goal should have come before the estate. But I’d start establishing the estate on day one of any role, whatever the objectives turn out to be.
There are, broadly, two ways to get from where you are to where you want to be.
Note: I’ve never been sure everyone agrees which way round “top-down” and “bottom-up” go. I’ll describe them the way I picture them, but be aware others may use the inverse!
Top-Down
Knowing what the product does, how would you write it from scratch? As a team, sketch the system you’d want: the stack, the architecture, the deployment, security and resilience. That ideal system, which will change as you learn more, is your goal. The question becomes how you arrive at it iteratively.
Because the alternative is the big rewrite, and I’ve watched that go wrong more than once.
One company I worked for was writing a new web product in parallel with maintaining a thick WinForms one. I don’t know if they ever got there, but I had the distinct impression the new product could never catch up with the old. Another had been through three attempts at a rewrite. Each ended when the money or the motivation ran dry, and was scrapped in favour of the much more stable, much more complete original. By the time I joined, they’d bought every user a second monitor so they could run both systems side by side, entering every piece of data twice.
If your plan is File → New Solution and one day flicking a switch, chances are you’re doomed. I’ve heard from proud CTOs where that gamble paid off, but it’s a massive and unnecessary one. Mostly what you get is an incomplete fork that’s shelved when the cash runs out, or forced on users with half the features, causing them no end of pain.
So work in slices instead, each one moving a little more of the estate into your ideal system, and each one shippable on its own. And no, you don’t need to plan every slice of the current product up front. You’d be planning against an estate you only half understand, and the plan would be wrong by the second slice anyway. I look for three things:
- The hardest path: the area everyone is scared to touch.
- The hottest path: the most used. Those web server logs from your mining earn their keep here.
- The most requested area: wherever users keep asking for changes.
Then I sit down with the team and the stakeholders and decide which of those goes first. Once that slice is done, run the analysis again. The estate will look different from the other side of it, and so will the priorities.
Bottom-Up
I’ve also worked in places where “migration” and “rewrite” were too big and scary to be uttered at all. Sometimes that’s worth fighting; it may be a fear of the unknown, or a misunderstanding of what’s involved, that a conversation can fix.
When it isn’t, I fall back on bottom-up, which is little more than the boy scout rule with the line in the sand drawn a bit further out. These places are often stuck in a loop of firefighting the latest problem as quickly as possible, each hack making the next fire more likely. The way out is to move the line: step up from tidying variable names to getting tests in, and from there to moving the worst areas over, driven by whatever the customers need next.
You stay in a hybrid state for longer than you would top-down. But if you’re focusing on the problem areas, whatever legacy code lingers presumably isn’t doing much harm. Better yet, you don’t need anyone’s permission. Rather than telling a product owner “if I do it properly it’ll take this long, but I can hack it in quicker”, I only give estimates based on my line in the sand.
There’s a pragmatic vs. dogmatic balance to strike, mind you. Leave your stakeholders in a bind and you’re doing your company more harm than good, whatever your intentions. As the bug count falls and confidence in the team grows, you may well find the door to the top-down approach creaking open anyway.
Here’s the good news, though. In 2026 both approaches arrive at the same technique.
Strangling it
Martin Fowler called it the strangler fig: a new application grows around the old one, takes over a piece at a time, and the old one is eventually left with nothing to do.
In 2017 I was describing this as the proxy technique, and it came with an apology about unpublished repositories. /sigh. It’s now Microsoft’s own recommended path, built from two shipped pieces:
- YARP, a reverse proxy that runs inside an ASP.NET Core application.
- The System.Web adapters,
which let the new application share session state and authentication with the old one, and let
your class libraries compile against
HttpContexton both.
The shape is simple. A new ASP.NET Core application goes in front, on the domain the users already know. Anything it has a route for, it handles. Everything else falls through to the Web Forms application, which now sits behind it:
┌─────────────────────────────┐
request ──►│ ASP.NET Core (.NET 10) │── /orders/history ──► new code
│ YARP fallback route │
└──────────────┬──────────────┘
│ everything else
▼
┌─────────────────────────────┐
│ Web Forms (.NET Fx 4.8.1) │
│ remote session + auth │
└─────────────────────────────┘
On day one, the new application has no routes of its own and forwards everything. Users notice nothing. That’s the point: you can put it live, at the speed a DNS change propagates, before you’ve migrated a single page.
The new application
On the ASP.NET Core side, Program.cs registers the adapters, points them at the old application,
and adds the fallback route as follows:
using Microsoft.AspNetCore.SystemWebAdapters;
using Microsoft.Extensions.Options;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSystemWebAdapters()
.AddJsonSessionSerializer(options => options.RegisterKey<int>("BasketCount"))
.AddRemoteAppClient(options =>
{
options.RemoteAppUrl = new(builder.Configuration["RemoteAppUri"]!);
options.ApiKey = builder.Configuration["RemoteAppApiKey"]!;
})
.AddSessionClient()
.AddAuthenticationClient(true);
builder.Services.AddReverseProxy();
builder.Services.AddOrderHistory();
var app = builder.Build();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseSystemWebAdapters();
app.MapOrderHistory();
app.MapForwarder(
"/{**catch-all}",
app.Services.GetRequiredService<IOptions<RemoteAppClientOptions>>().Value.RemoteAppUrl.OriginalString)
.WithOrder(int.MaxValue)
.ShortCircuit();
app.Run();
AddOrderHistory and MapOrderHistory are the first slice you’ve moved over. Everything else hits
the catch-all, which runs last (WithOrder(int.MaxValue)) and short-circuits the rest of the
pipeline, so remote authentication isn’t attempted on requests the old application will handle
anyway.
Note: back in 2017, both MVC and the proxy middleware terminated the pipeline, which meant hand-mapping every request to one or the other. Endpoint routing made that whole section of the old draft redundant. It’s the one bit of rot I was glad to delete.
The old application
On the Web Forms side, the matching half goes in Application_Start in Global.asax.cs:
protected void Application_Start()
{
HttpApplicationHost.RegisterHost(builder => builder.AddSystemWebAdapters()
.AddJsonSessionSerializer(options => options.RegisterKey<int>("BasketCount"))
.AddProxySupport(options => options.UseForwardedHeaders = true)
.AddRemoteAppServer(options => options.ApiKey = ConfigurationManager.AppSettings["RemoteAppApiKey"])
.AddSessionServer()
.AddAuthenticationServer());
}
There’s also a module entry for web.config and an appSettings key; the
remote app setup guide
has both, and is worth reading against whichever package version you install, because these calls
have shifted between releases.
A few things the guide says that are easy to skim past:
- Every session key needs registering, on both sides, with its type. Web Forms serialised
session with
BinaryFormatter; the adapters don’t, and an unregistered key is an error rather than a quietnull. Your estate notes should already tell you which keys exist. If they don’t, that’s your next bit of mining. - The API key must parse as a GUID and match on both sides. Keep it in configuration, not code.
- The old application should only be reachable through the new one. Lock it down at the network, not just by hoping nobody finds the old hostname.
- Windows authentication isn’t supported by remote authentication, and logging in and out still goes through the old application until you move it.
Moving a slice
From here, migrating is the same small loop, over and over:
- Pick the next slice: the hardest, hottest or most requested, as agreed above.
- Rebuild its routes in the new application, with tests.
- Ship it. The new routes now win, and the fallback stops seeing that traffic.
- Watch the logs on both sides until you’re confident nothing still reaches the old pages.
- Delete the old pages.
- Re-run the analysis, because the next slice may not be the one you expected.
One caveat on that first pick. If you’ve never run the proxy in production, prove the plumbing on something boring and read-only before you aim it at the scariest part of the estate. Find out whether session sharing works on a page nobody will ring you about.
I’m going to labour step five, because it’s the one everyone skips. Many a time I’ve stumbled across orphaned code and, without the context that it had just been replaced, the decision to remove it was much harder than it should have been. If it’s been strangled, bury it. Source control still has the old pages if you ever need to look something up.
Shared class libraries get the same treatment in miniature. Where they reach for HttpContext,
swap the System.Web reference for the Microsoft.AspNetCore.SystemWebAdapters package and
multi-target them, so the same code compiles for both applications while the move is underway.
Getting tests in first
Step two said with tests, and that’s easy enough in the new application. The harder question is what you do about the logic still trapped in code-behind files, which is where bottom-up lives and dies.
The reason Web Forms has always resisted dependency injection is that the framework constructs your
pages for you, and it insisted on a public parameterless constructor to do it. No parameters, no
(constructor) injection. In 2017 my answer was an IHttpModule that hunted for the greediest
constructor and invoked it by reflection on a page that already existed. It worked. I wouldn’t wish
it on anyone.
You could reach for the Service Locator
instead, but you should not. And since .NET Framework 4.7.2 you don’t need to, because Web Forms
gained a hook for exactly this: HttpRuntime.WebObjectActivator. Give it an IServiceProvider and
the framework asks it for pages, user controls and master pages, constructor parameters and all.
The catch is that it asks for almost everything, including plenty of its own internal types that your container has never heard of. So the provider needs to fall back gracefully, something like the following:
using System;
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
namespace Shop.Web;
internal sealed class ServiceProviderActivator(IServiceProvider services) : IServiceProvider
{
const BindingFlags _AnyInstanceConstructor =
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance;
public object? GetService(Type serviceType)
=> services.GetService(serviceType) ?? Create(serviceType);
object? Create(Type type)
=> type.GetConstructors().Any(constructor => constructor.GetParameters().Length > 0)
? ActivatorUtilities.CreateInstance(services, type)
: Activator.CreateInstance(type, _AnyInstanceConstructor, null, null, null);
}
Anything registered comes from the container. Anything with dependencies is built by
ActivatorUtilities from the container. Everything else is built the way Web Forms would have built
it anyway. It’s wired up once, in Application_Start, which becomes your
Composition Root:
HttpRuntime.WebObjectActivator = new ServiceProviderActivator(
new ServiceCollection()
.AddOrderHistory()
.BuildServiceProvider());
And now a page can say what it needs, like any other class:
public partial class OrderHistory(OrderHistoryQuery history) : Page
{
protected void Page_Load(object sender, EventArgs e)
{
Orders.DataSource = history.ForCurrentCustomer();
Orders.DataBind();
}
}
As you can see, the page is now almost nothing. That’s the real win. The logic lives in
OrderHistoryQuery, which you can test today, in the old application, and which moves to the new
application largely untouched when the route is strangled. The page itself is what gets deleted.
Note: both
targetFrameworkattributes inweb.config(httpRuntimeandcompilation) need to say 4.7.2 or later, or you’ll get the old “no parameterless constructor” error and a wasted afternoon. Primary constructors and file-scoped namespaces are compiler features rather than runtime ones, so they work on .NET Framework with<LangVersion>latest</LangVersion>; an old-style project defaults to C# 7.3 otherwise.
Summary
None of this is a silver bullet, and as ever your mileage will vary, so don’t take it for gospel. But if I were sat in front of a Web Forms estate tomorrow, I’d:
- Establish the estate first, with tact, and come away with a list of routes and session keys.
- Put the new application in front on day one, forwarding everything, before migrating anything.
- Get the logic out of the code-behind with
WebObjectActivator, so it’s tested before it moves. - Move a slice at a time (hardest, hottest or most requested), delete what you replaced, then re-run the analysis.
- Never schedule a switch-over day. If you find yourself planning one, you’ve drifted back into the big rewrite.
If you’ve done this recently, especially with a large estate, I’d genuinely like to hear what bit you. The comments are below.