Covers the classic ASP.NET stack (System.Web, IIS integrated pipeline, Global.asax, HttpModules, HttpContext.Current, web.config, separate MVC and Web API) and the ASP.NET Core equivalents (Program.cs, middleware, IHttpContextAccessor, appsettings.json, unified MVC).
Classic ASP.NET sits on System.Web.dll, which is bound to IIS and Windows. MVC 5 and Web API 2 were two separate frameworks: different controller base classes (Controller vs ApiController), filters, routing and DI hooks. App start-up lived in Global.asax, cross-cutting code in HttpModules, request data came from the ambient HttpContext.Current, and settings came from web.config.
ASP.NET Core replaces all of that: one MVC framework for pages and APIs, Program.cs for start-up, middleware for modules, HttpContext passed explicitly (or IHttpContextAccessor), appsettings.json plus environment variables via the options pattern, and built-in DI. The trade-off: it is faster and cross-platform, but nothing in System.Web compiles against it unchanged.
"Classic ASP.NET is built on
System.Web.dll, which is basically the IIS integrated pipeline exposed to .NET. Everything hangs off it:HttpApplicationandGlobal.asaxfor start-up and app events, HttpModules for things like authentication and logging, HttpHandlers for endpoints, andHttpContext.Current, a static property that gives any code anywhere the current request. Configuration isweb.config: XML that mixes app settings, connection strings, IIS settings and assembly binding redirects.On top of that sat two frameworks. MVC 5 for HTML, with
ControllerinSystem.Web.Mvc, and Web API 2 for JSON, withApiControllerinSystem.Web.Http. They looked similar but had separate routing, filters, model binding and dependency resolvers, so registering a filter in one didn't apply to the other. DI wasn't built in; you plugged in Autofac or Unity.ASP.NET Core merges MVC and Web API into one framework, and replaces each piece.
Program.csreplacesGlobal.asax. Middleware replaces modules and handlers.appsettings.json, environment variables and the options pattern replaceweb.configapp settings. DI is built in. AndHttpContextis passed to you: in a controller it's a property, and anywhere else you injectIHttpContextAccessor. The mistake I see is treatingIHttpContextAccessoras a drop-in forHttpContext.Currentand injecting it everywhere, which drags request state into business logic. Better to pass the values you need, like the user ID, as parameters. The senior line:System.Webis not a library you can upgrade, it's the platform, so a migration replaces the hosting model, not just the code."
| Classic ASP.NET (System.Web) | ASP.NET Core (.NET 10) |
|---|---|
Global.asax Application_Start |
Program.cs top-level statements |
HttpModule (BeginRequest, AuthenticateRequest) |
Middleware (app.Use...) |
HttpHandler (.ashx) |
Endpoint (app.MapGet) or controller action |
HttpContext.Current |
HttpContext parameter / ControllerBase.HttpContext / IHttpContextAccessor |
web.config <appSettings>, <connectionStrings> |
appsettings.json, environment variables, user secrets, Key Vault, IOptions<T> |
ConfigurationManager.AppSettings["Key"] |
IConfiguration["Key"] or bound IOptions<T> |
System.Web.Mvc.Controller + System.Web.Http.ApiController |
One Microsoft.AspNetCore.Mvc.ControllerBase / Controller |
GlobalFilters and config.Filters (two sets) |
One filter pipeline, plus endpoint filters for minimal APIs |
DependencyResolver.SetResolver(...) |
builder.Services built-in container |
Session on by default (in-proc) |
Session opt-in, backed by IDistributedCache |
Runs inside IIS (w3wp.exe) |
Runs on Kestrel; IIS in-process or as reverse proxy via ANCM |
| Area | Classic | Core |
|---|---|---|
| Synchronous I/O | Allowed | Blocked by default on Kestrel (AllowSynchronousIO = false) |
| Request body | Can be read many times | Forward-only stream; call EnableBuffering() to re-read |
| JSON | Newtonsoft.Json | System.Text.Json (case-sensitive by default outside MVC, different date handling) |
| Bundling | System.Web.Optimization |
Build-time tooling or MapStaticAssets |
When a team I would describe as typical moves a Web API 2 service to ASP.NET Core, the most common surprises are JSON differences (property casing, DateTime format, reference loops) and HttpContext.Current returning null in background code. Catching those needs contract tests that compare old and new responses byte for byte; a service with 120 endpoints commonly finds 5–10 that serialise differently.
Checks that the candidate can map classic ASP.NET concepts to ASP.NET Core and knows why it is a new hosting model, not an upgrade.
Green flags
System.Web is tied to IISGlobal.asax, modules, HttpContext.Current and web.config correctlyRed flags
IHttpContextAccessor everywhere without caveatsappsettings.jsonSystem.Web.dll is the managed half of the IIS integrated pipeline. IIS raises events for every request, and HttpApplication exposes them to .NET:
IIS (w3wp.exe)
└─ HttpApplication (Global.asax)
BeginRequest → AuthenticateRequest → AuthorizeRequest →
ResolveRequestCache → AcquireRequestState (Session) →
[HttpHandler executes: MvcHandler / Web API / Page] →
ReleaseRequestState → EndRequest
(HttpModules subscribe to any of these events)
Because this is IIS-shaped, it can't run on Linux or in Kestrel, and it can't be split into a NuGet package. That is why ASP.NET Core is a new framework rather than a new version.
HttpContext.Current reads the context from the current logical call context. In classic ASP.NET it flows across await only when the app runs with the task-friendly SynchronizationContext (<httpRuntime targetFramework="4.5" /> or later). On a raw thread-pool thread or Task.Run without that context, it is null. It is global state: any class can reach it, which makes code hard to test.
ASP.NET Core removed the static. IHttpContextAccessor stores the context in an AsyncLocal<T>, so it flows with async code, but it is only valid while the request runs. Capturing it in a background task and reading it later gives a disposed or recycled context.
web.config is XML read by ConfigurationManager. It contains app settings, IIS settings (<system.webServer>), runtime binding redirects and sometimes secrets. Changing it restarts the app domain.
ASP.NET Core configuration is a stack of providers, later ones winning:
appsettings.json → appsettings.{Environment}.json → user secrets (dev)
→ environment variables → command line → (Azure App Configuration / Key Vault)
Values are bound to typed classes with IOptions<T>, validated at start-up with ValidateOnStart(), and can reload without restarts via IOptionsMonitor<T>. When hosted in IIS, a small web.config still exists, but only to configure the ASP.NET Core Module.
MVC 5 and Web API 2 had duplicate abstractions:
| Concern | MVC 5 | Web API 2 |
|---|---|---|
| Base class | System.Web.Mvc.Controller |
System.Web.Http.ApiController |
| Result | ActionResult |
IHttpActionResult / HttpResponseMessage |
| Filters | System.Web.Mvc.IActionFilter |
System.Web.Http.Filters.IActionFilter |
| DI hook | DependencyResolver |
HttpConfiguration.DependencyResolver |
ASP.NET Core has one of each. [ApiController] adds the API behaviours (automatic 400 for invalid models, binding source inference).
Global.asax.cs and web.config sections; map each to its ASP.NET Core equivalent.BeginRequest/EndRequest.HttpContextAccessor.HttpContext inside Task.Run after the request has finished and observe it is null or invalid.appsettings.json to a record with ValidateDataAnnotations().ValidateOnStart() and start the app with a missing value.Classic Web API 2 controller and its ASP.NET Core equivalent.
// Before: Web API 2 on .NET Framework 4.8
using System.Configuration;
using System.Web;
using System.Web.Http;
public class InvoicesController : ApiController
{
[HttpGet, Route("api/invoices/{id:int}")]
public IHttpActionResult Get(int id)
{
var userId = HttpContext.Current.User.Identity.Name; // ambient static
var maxDays = int.Parse(ConfigurationManager.AppSettings["InvoiceMaxDays"]); // web.config
// ... load invoice ...
return Ok(new { id, userId, maxDays });
}
}
// After: ASP.NET Core on .NET 10
namespace Billing.Api;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
public sealed record InvoiceOptions
{
public int MaxDays { get; init; } = 30;
}
[ApiController]
[Route("api/invoices")]
public sealed class InvoicesController(IOptions<InvoiceOptions> options) : ControllerBase
{
[HttpGet("{id:int}")]
public IActionResult Get(int id, CancellationToken ct)
{
var userId = User.Identity?.Name; // HttpContext.User, passed in, no static
return Ok(new { id, userId, options.Value.MaxDays });
}
}
// Program.cs replaces Global.asax and the configuration parts of web.config
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOptions<InvoiceOptions>()
.Bind(builder.Configuration.GetSection("Invoice"))
.ValidateOnStart();
builder.Services.AddControllers();
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();
// appsettings.json replaces <appSettings> in web.config
{
"Invoice": { "MaxDays": 30 }
}
HttpContext.Current with an injected IHttpContextAccessor. Why it is wrong: It keeps request state leaking into business logic and breaks in background work. Instead: Read what you need in the controller and pass plain values (user ID, tenant) down.web.config into appsettings.json in git. Why it is wrong: Secrets end up in source control. Instead: Use user secrets locally and Key Vault or environment variables in Azure.AddNewtonsoftJson() temporarily.The big idea is that classic ASP.NET is a platform (IIS plus System.Web) and ASP.NET Core is a library you host. That's why migration feels like moving house, not repainting. Merging MVC and Web API didn't remove API-specific features: [ApiController] gives automatic 400 ProblemDetails responses and binding-source inference, and minimal APIs are a lighter option for pure HTTP APIs. Built-in constructor injection replaces DependencyResolver and service-locator calls, so controllers declare their dependencies and can be unit tested by passing fakes. Because synchronous I/O is blocked by default, data access and outbound calls need to become async as part of the move. For large apps, Microsoft's System.Web adapters let you keep using familiar HttpContext shapes in shared libraries while you move controllers across, and contract tests that compare old and new responses catch JSON and status-code drift.
| Approach | When it fits | Cost | When not to |
|---|---|---|---|
| Port controllers straight to ASP.NET Core | Small API, good tests | Low to medium | Lots of System.Web in shared libraries |
| System.Web adapters plus incremental move | Large MVC 5 app, shared libraries use HttpContext |
Medium, temporary shims | New greenfield code |
| Keep Newtonsoft.Json during migration | Many clients depend on exact JSON | Small perf cost | After contracts are pinned with tests |
Middleware is a component in the request pipeline: a RequestDelegate that receives the HttpContext, can do work, calls next to pass the request on, and can do more work when the response comes back. It can also short-circuit by not calling next. Use adds middleware that may call next; Run adds terminal middleware; Map branches the pipeline by path; UseWhen branches on a condition and rejoins, MapWhen branches without rejoining. Because each middleware wraps the next, order is behaviour: exception handling first, then HTTPS, static files, routing, CORS, authentication, authorisation and finally endpoints. Custom middleware can be convention-based (a class with InvokeAsync, created once as a singleton) or implement IMiddleware (resolved from DI per request). The trade-off: convention-based is the fastest default; IMiddleware is clearer when you need scoped dependencies.
The Generic Host (IHost) is the common runtime shell for every modern .NET app, web or worker: it owns configuration, logging, dependency injection and the application lifetime. WebApplication.CreateBuilder(args) creates one with sensible defaults: appsettings.json, appsettings.{Environment}.json, user secrets in Development, environment variables and command-line args; console, debug and EventSource logging; and Kestrel. Build() freezes the service collection and builds the IServiceProvider. Run() starts hosted services, then the web server, and blocks until shutdown. On SIGTERM or Ctrl+C the host fires ApplicationStopping, stops accepting requests, lets in-flight ones finish, stops hosted services and exits within HostOptions.ShutdownTimeout (30 seconds by default). The trade-off: the defaults are great, but you must understand them to override them deliberately.
IHttpContextAccessor stores the current context in an AsyncLocal, so it flows with the request's async calls and is valid only while the request runs. Fire-and-forget work, Task.Run that outlives the request, or a singleton reading it later can see null or a recycled context from another request, because HttpContext objects are pooled. HttpContext is also not thread-safe: reading or writing it from parallel tasks, even during the request, can race and corrupt state. Don't capture scoped services (like a DbContext) either; they are disposed when the request scope ends. Instead, copy the values you need (user ID, correlation ID, tenant) into a message or parameters before starting the work, create a new DI scope in the background worker, and use a queue (Channel<T> with a BackgroundService) for anything that must outlive the request.
Last updated 23 Nov 2026.