I disagree with these answers and the pointlessness of having only an HttpContext in a web project. This is actually closely related, since YOU want to be able to reuse the code and therefore the class library in the .net core OR .net standard MUST be able to use HttpContext
So, in .NET Standard you want to add:
Microsoft.AspNetCore.Http.Abstractions
Unfortunately, although there are so many differences in the new HttpContext, HttpContext.Current missing and therefore the session, request, etc.
(Yes, I get design patterns and why highlight them and make them more testable)
Here is a little trick you can do to get Current
namespace System.Web { public static class HttpContext { private static Microsoft.AspNetCore.Http.IHttpContextAccessor m_httpContextAccessor; public static void Configure(Microsoft.AspNetCore.Http.IHttpContextAccessor httpContextAccessor) { m_httpContextAccessor = httpContextAccessor; } public static Microsoft.AspNetCore.Http.HttpContext Current { get { return m_httpContextAccessor.HttpContext; } } } }
source share