Home / Incremental .NET modernisation
Legacy application modernization
Modernise a legacy .NET app without a rewrite
A new ASP.NET Core app goes in front of the old one. It serves the routes that have moved and passes everything else through to .NET Framework, so the app stays in production while it moves to .NET 10, one route at a time. Microsoft calls this incremental migration; architects call it the strangler fig pattern.
// New ASP.NET Core app, in front of the old one
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSystemWebAdapters();
builder.Services.AddHttpForwarder();
builder.Services.AddRazorPages();
var app = builder.Build();
app.UseSystemWebAdapters();
app.MapRazorPages(); // routes moved so far
app.MapForwarder("/{**catch-all}",
app.Configuration["ProxyTo"]); // the rest
app.Run();
Strangler fig pattern
How the strangler fig pattern works
The pattern is named after a vine that grows around a tree until it can stand on its own. A facade, here a reverse proxy, takes every request and decides which system answers it. Users keep the same URLs and see one application throughout.
The facade goes in
The new ASP.NET Core app is put in front of the old one. At first it forwards almost every request to the .NET Framework app.
Routes move across
Pages, controllers and API endpoints are rebuilt in the new app one at a time. Each goes live as soon as it is ready, and the proxy stops forwarding it.
The old app is switched off
Once nothing is forwarded any more, the .NET Framework app is decommissioned.
The facade goes away
With only one app left, the forwarding is removed. The new app is simply the app.
Incremental, in place or rewrite
Which way to move a .NET Framework app
Microsoft describes two routes for ASP.NET apps: incremental migration for larger apps that must stay in production, and in-place migration for apps small enough to move in one go. A full rewrite is the third option teams consider.
| Incremental (strangler fig) | In place | Rewrite | |
|---|---|---|---|
| App in production | Throughout | Old version until cutover | Old version until the new one is finished |
| Goes live | Route by route | All at once | All at once |
| Fits | Large apps, unknown dependencies, heavy System.Web use | Small or medium apps with few dependencies | Apps whose behaviour is being redesigned anyway |
| Extra work | Proxy, shared session and sign-in while both apps run | None beyond the port | Rebuilding every feature, and finding the ones nobody wrote down |
| Main risk | Running two apps for a while | A long branch that has to land in one go | Value only once everything is done |
Source: Microsoft Learn: migrate from ASP.NET Framework to ASP.NET Core.
YARP and the System.Web adapters
Keeping two apps looking like one
Routing is the easy part. The work is in the things both apps have to agree on while they run side by side.
Routing. The new app uses YARP (Yet Another Reverse Proxy) to forward any request it does not handle to the old app, as in the Program.cs above. Moving a route is a deployment of the new app, not a change to the old one.
Session state. .NET Framework serializes session objects for you and locks the session per request; ASP.NET Core does neither. With Microsoft's remote app session, the new app reads and writes the old app's session, with each key registered so it can be serialized as JSON instead of with BinaryFormatter.
Sign-in. With remote authentication the new app asks the old one who the user is, which covers forms, Windows and most custom authentication. Apps that already use OWIN cookie authentication can share the cookie instead, provided both use the same data protection keys.
Shared code. Libraries used by both apps are moved to .NET Standard 2.0 where possible, so one build serves both. The System.Web adapters let that code keep calling HttpContext while the web layer moves.
Where it starts
The first four steps of an incremental migration
These are the steps Microsoft sets out before the first route moves. Visual Studio 2022 or later and the .NET 8 or later SDK are needed.
Set up the ASP.NET Core app
A new ASP.NET Core project sits alongside the old one, with YARP forwarding everything to it, and is deployed in front of it before any route moves.
Clear the technical debt that blocks the move
Update packages one at a time, move to
PackageReferenceand SDK-style projects, fix compiler warnings and remove dead code, so the move starts from a clean build.Find the cross-cutting concerns
Session, authentication, logging, caching, error handling, configuration and dependency injection touch every route, so each needs a decision before routes start moving.
Move the libraries the first routes need
Only the libraries those routes use, starting from the ones with no dependencies of their own, retargeted to .NET Standard 2.0 where possible.
Source: Microsoft Learn: get started with incremental ASP.NET to ASP.NET Core migration. Web Forms pages have their own route: see ASP.NET Web Forms migration. For the wider choice of target, see .NET Framework 4.8 to .NET 10.
When it doesn't fit
When not to use the strangler fig pattern
The pattern adds moving parts, and the Azure Architecture Center is clear about when they are not worth it.
Requests can't be intercepted
If clients reach the old system in a way a proxy can't sit in front of, there is nowhere to put the facade.
No source and no integration point
Without the code, or at least an interface to call, there is nothing for the new app to take over piece by piece.
The app is small
A small, simple app is cheaper to move in place than to run as two apps for a while.
The old system must go fast
The pattern is gradual by design. If the old platform has to be switched off on a fixed early date, a direct replacement is the safer bet.
Even where it fits, keep the proxy from becoming a single point of failure or a bottleneck, plan for data the two systems share, and budget for the temporary infrastructure.
Modernisation cost
What drives the cost of legacy .NET modernisation
There is no honest price per line of code. The estimate comes from a handful of things the audit counts.
Routes and pages
How many there are, and how much logic sits in each one rather than in shared libraries.
Cross-cutting concerns
Which of session, sign-in, caching, logging and configuration have to be shared while both apps run, and how unusual each one is.
Library depth
How many internal and third-party libraries the routes depend on, and whether each has a modern .NET version or needs replacing.
Session and sign-in type
Forms or Windows authentication and simple session values are well supported. Custom authentication and complex objects kept in session take more work.
Parts that don't port
Web Forms pages, WCF services and anything using BinaryFormatter or .NET Remoting are rebuilt rather than retargeted. See WCF to CoreWCF, gRPC or Web API.
Questions
Incremental .NET modernisation FAQ
What is the strangler fig pattern?
A way to replace a legacy system piece by piece instead of all at once. A facade, usually a reverse proxy, sits in front of the old system and sends each request either to the old system or to the new one. Users keep the same address and see one application. As features move, more requests go to the new system, until the old one can be switched off and, in the end, the facade removed. Microsoft documents it in the Azure Architecture Center, and its incremental ASP.NET migration guidance is built on it.
What is YARP and why is it used for .NET migration?
YARP (Yet Another Reverse Proxy) is Microsoft's reverse proxy library for ASP.NET Core. In an incremental migration the new ASP.NET Core app handles the routes that have moved and uses YARP to forward every other request to the old .NET Framework app. That makes the new app the single front door, so routes can move one at a time without users noticing.
Should we migrate incrementally or all at once?
Microsoft's guidance is to migrate incrementally when the app must stay in production, is large, has dependencies you don't fully know, or relies heavily on System.Web. A small or medium app with few dependencies can often be moved in place in one go, which is simpler because there is only ever one app to run.
How do the old and new apps share sessions and logins?
Through Microsoft's System.Web adapters. For session state, the remote app session option lets the ASP.NET Core app read and write the session held by the .NET Framework app, with each session key registered so it can be serialized as JSON. For sign-in, remote authentication lets the new app ask the old app who the user is, which works for forms, Windows and most custom authentication. If both apps use OWIN cookie authentication, they can share the cookie instead.
Is incremental migration slower than a rewrite?
It can take longer from start to finish, because two apps run side by side and the proxy and shared state are extra work. In exchange there is no big-bang cutover: each route goes live when it is ready, the old app keeps earning while the work happens, and the riskiest or most valuable parts can move first. A rewrite only pays off when the whole thing is finished.
When is the strangler fig pattern a bad fit?
When requests to the old system cannot be intercepted, when there is no source code and no integration point to work with, when the system is small enough to replace in one go, or when the old system has to be switched off quickly. In those cases an in-place migration or a straight replacement is usually the better choice.
Find out what modernising your .NET app would take
A fixed-price audit from US$500: routes, libraries and cross-cutting concerns mapped, the right route chosen (incremental, in place or rebuild), and a step-by-step plan with an estimate. Working with .NET since 2009.