When migrating a large ASP.NET Framework app to ASP.NET Core 10 incrementally, what do the System.Web adapters do, and where do they stop helping?
answer
- new app in front, old app behind
- Microsoft.AspNetCore.SystemWebAdapters for shared libraries
- CoreServices on Core, FrameworkServices on Framework
- AddRemoteAppClient with a GUID ApiKey
- RequireSystemWebAdapterSession per endpoint
basics
~20 sThe System.Web adapters re-implement part of System.Web, such as HttpContext and session, on ASP.NET Core, so System.Web-based libraries run in both apps while routes move over. They adapt APIs, not page frameworks, and remote session costs round trips.
solid answer
~50 sIncremental migration puts a new ASP.NET Core app in front of the Framework app: routes that have moved are served by Core, everything else is forwarded to the old app by a reverse proxy. The adapters make that survivable for shared code. `Microsoft.AspNetCore.SystemWebAdapters` gives class libraries `System.Web.HttpContext`, `HttpContext.Current` and friends backed by ASP.NET Core's `HttpContext` (and type-forwards to the real System.Web on .NET Framework), so one library builds for both apps. `Microsoft.AspNetCore.SystemWebAdapters.CoreServices` wires the Core app with `AddSystemWebAdapters()`, `UseSystemWebAdapters()` and `AddRemoteAppClient`, and `FrameworkServices` wires the old app with `AddRemoteAppServer`, so Core can fetch session state and authentication from the Framework app using a shared GUID API key. They stop helping where the API surface ends: they cover a subset of System.Web, not Web Forms pages, session works only on endpoints marked for it, and every remote session or auth call adds a hop. They are scaffolding to remove when the last route moves.
code
csharp · 23 linesvar builder = WebApplication.CreateBuilder(args);
builder.Services.AddSystemWebAdapters()
.AddJsonSessionSerializer(o => o.RegisterKey<int>("LoyaltyTier"))
.AddRemoteAppClient(options =>
{
options.RemoteAppUrl = new Uri(builder.Configuration["RemoteAppUri"]!);
options.ApiKey = builder.Configuration["RemoteAppApiKey"]!;
})
.AddSessionClient();
var app = builder.Build();
app.UseRouting();
app.UseSystemWebAdapters();
app.MapGet("/bookings/{id:int}", (int id) =>
{
var tier = System.Web.HttpContext.Current?.Session?["LoyaltyTier"];
return Results.Ok(new { id, tier });
}).RequireSystemWebAdapterSession();
app.Run();go deeper
Know that incremental migration runs an ASP.NET Core app in front of the old Framework app and moves routes over time.
Explain which adapters package each project references and how shared libraries keep using System.Web types.
Plan session and authentication sharing with the remote-app client and server, and weigh the latency and surface limits.
Set exit criteria so the adapters and the Framework app are retired on a schedule rather than becoming a permanent layer.
## Incremental migration in one picture A big ASP.NET Framework app (MVC 5, Web API 2, Web Forms, often all three) rarely moves to ASP.NET Core in one release. The incremental approach runs **two apps side by side**: - A new **ASP.NET Core 10** app receives all traffic. - Routes already migrated are served by it directly. - Every other request is forwarded to the **ASP.NET Framework** app by a reverse proxy configured as a low-priority fallback route; the proxy itself is a separate topic. - Over months, routes move from the old app to the new one until the Framework app serves nothing and is switched off. The hard part is not routing. It is the **code and state the two apps share**: class libraries that take `System.Web.HttpContext`, `HttpContext.Current` sprinkled through business logic, session values one app writes and the other reads, and a logged-in user that must stay logged in across both. That is what the System.Web adapters address. ## The packages | Package | Referenced by | Provides | |---|---|---| | `Microsoft.AspNetCore.SystemWebAdapters` | shared class libraries | a subset of System.Web types backed by ASP.NET Core; type-forwards to System.Web on .NET Framework; targets .NET Standard 2.0, .NET Framework and .NET | | `Microsoft.AspNetCore.SystemWebAdapters.CoreServices` | the ASP.NET Core app | `AddSystemWebAdapters()`, `UseSystemWebAdapters()`, the remote-app client, session and authentication clients | | `Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices` | the ASP.NET Framework app | the remote-app server side, session and authentication servers, a module added to `web.config` | | `Microsoft.AspNetCore.SystemWebAdapters.Abstractions` | both | shared abstractions such as session serialisation | ## What a shared library gets A library that calls `HttpContext.Current.Request.Headers["X-Hotel"]` can reference the adapters package instead of `System.Web.dll`, often retarget to .NET Standard 2.0, and compile **unchanged** for both apps. On ASP.NET Core, `System.Web.HttpContext` is a wrapper over the request's `Microsoft.AspNetCore.Http.HttpContext`; you convert between them with implicit casts or with `AsSystemWeb()` and `AsAspNetCore()`, and the wrapper is cached for the request. On .NET Framework the same types forward to the real System.Web, so nothing changes there. ## Sharing state with the Framework app 1. In the Core app, `builder.Services.AddSystemWebAdapters()` registers the adapters, and `app.UseSystemWebAdapters()` adds their middleware after routing. 2. `AddRemoteAppClient(options => ...)` points at the Framework app through `RemoteAppUrl` and authenticates with `ApiKey`, a value that must be GUID-shaped and identical on both sides. 3. `AddSessionClient()` plus `AddJsonSessionSerializer(o => o.RegisterKey<int>("LoyaltyTier"))` lets Core read and write the Framework app's session; every session key needs a registered type so it can be serialised as JSON. 4. `AddAuthenticationClient(true)` registers remote authentication as the default scheme, so the Framework app authenticates the current user and a cookie issued by the old login page still works on migrated routes. 5. The Framework app mirrors this with `AddRemoteAppServer`, `AddSessionServer` and `AddAuthenticationServer`. Session is **opt-in per endpoint**: an endpoint gets `System.Web` session only when it is marked with `[Session]` or `.RequireSystemWebAdapterSession()`. ## Where they stop helping - **They adapt APIs, not page frameworks.** Web Forms pages, user controls and other Framework UI are not hosted on Core; they are rewritten as Razor Pages, MVC views or Blazor components. - **The surface is a subset.** Members that ASP.NET Core cannot honour are missing; for example, positional `Get(int)` access on the `NameValueCollection`-shaped header collections is unavailable. - **Remote state costs latency.** A remote session or authentication call is an extra HTTP round trip to the Framework app per request that needs it, which is why session is opt-in. - **They are scaffolding.** Each adapter call is a place the code still thinks in System.Web; the end state is native ASP.NET Core APIs and no Framework app. ## An exit plan Track three counters per release: routes still forwarded, endpoints still requiring remote session, and libraries still referencing the adapters. When all three reach zero, remove the packages and the proxy fallback, and the migration is done.
- Why does an endpoint have to opt in to System.Web session?Because with remote session the state lives in the Framework app: loading it is a remote call, and a writable session keeps that connection open for the request and sends the changes back in a second call at the end. Making it opt-in with [Session] or RequireSystemWebAdapterSession keeps that cost on the endpoints that need it.
- Can a shared library keep using HttpContext.Current after moving to the adapters?Yes: the adapters package provides System.Web.HttpContext.Current backed by the current ASP.NET Core request, so such code compiles and runs in both apps. It is a migration aid, though; new code takes HttpContext or IHttpContextAccessor explicitly, and old call sites are worth replacing as each area moves.
- The System.Web adapters let Web Forms pages run unchanged on ASP.NET Core.
- Adding the adapters makes every endpoint load System.Web session automatically.
- The adapters implement all of System.Web, so no code needs to change.
- Remote session through the adapters is free because it reuses ASP.NET Core session.
- Once the adapters are in place the Framework app can be shut down.