'Error CS0234 The type or namespace name 'HttpContext' does not exist in the namespace 'System.Web' in asp.net core

enter image description here

CS0234 The type or namespace name 'Http Context' does not exist in the namespace 'System Web' in asp.net core



Solution 1:[1]

System.Web is not compatible with dotnet core and you mustn't try and reference it. In your case, if you are in a controller, you can access Request and Response properties directly.

Solution 2:[2]

HttpContext is a class contained in .Net framework but not .net core.

If you wanna access HttpContext in asp.net core, you can refer to this document, for example, in controller like code below:

public class HomeController : Controller
{
    public IActionResult About()
    {
        var pathBase = HttpContext.Request.PathBase;

        ...

        return View();
    }
}

and in other class, we need to inject service then use it, see this section for details.

Solution 3:[3]

Remove system.web.dll    
//1. install nuget package: "Microsoft.AspNetCore.Http"
    //2. create readonly property HttpContext 
    //3. create constructor and add argument HttpContext 
    //4. use "_context" instead of "system.web.HttpContext.currrent" in your code 
     
    //property:
            private readonly HttpContext _context;
    //constructor:
            public RegionalizeService(HttpContext context)
            {
                _context = context;
            }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Luke Briner
Solution 2
Solution 3 Prabhakaran M