Skip to main content

Posts

Showing posts with the label ASP.NET Core

Refactoring 'System.Web' Dependencies: Decoupling Legacy Logic for .NET 8 Migration

  The most significant barrier to migrating enterprise .NET Framework applications to .NET 8 (and consequently Linux containers) is the pervasive use of   System.Web.dll . For over a decade, developers treated  HttpContext.Current  as a global singleton, weaving it deep into business logic, logging frameworks, and helper classes. When you attempt to port this code to .NET Core/5+, the compiler fails immediately:  System.Web  does not exist. It was a Windows-specific, IIS-coupled assembly that has no place in the cross-platform, server-agnostic world of Kestrel. This post details the architectural pattern required to decouple these legacy dependencies using an abstraction layer that supports both the old ( System.Web ) and new ( Microsoft.AspNetCore.Http ) paradigms simultaneously. The Root Cause: Thread Static vs. AsyncLocal To fix the problem, you must understand why  HttpContext.Current  disappeared. In the legacy .NET Framework, IIS managed the...

Replacing System.Web.HttpContext.Current with IHttpContextAccessor in .NET 9 Migrations

  The most jarring obstacle when migrating legacy ASP.NET MVC applications (4.x) to .NET 9 is the disappearance of   System.Web . Specifically, the ubiquitous   HttpContext.Current   static property is gone. In legacy enterprise codebases, developers treated  HttpContext.Current  as a global singleton, accessing it inside static helper methods, business logic layers, and even data access layers to retrieve the current user, session data, or request IP. When you run the .NET Upgrade Assistant or manually port the code, you are immediately met with thousands of instances of  CS0103: The name 'HttpContext' does not exist in the current context . This post provides the architectural root cause and a rigorous strategy to mitigate this during migration without rewriting your entire business layer immediately. Root Cause Analysis: Why it was Removed System.Web.HttpContext.Current  was an architectural constraint tied directly to Internet Information Serv...