Let’s say, there is a class in .NET standard 2.0 project where class contains a method parameter of HttpContext. This class will be referenced in .NET 8 project.
Both projects use Microsoft.Aspnetcore.SystemWebAdapters NuGet.
In .NET 8, HttpContext is used with the help of IHttpContextAccessor and context.Session will be of type ISession.
I shall add few keys to this context’s Session.
Now, I have to call class method from .NET standard 2.0. When context object is passed in .NET standard, context.Session is null cause it refers System.Web namespace hence, session property is null.
Could somebody explain with small POC to handle session in such scenario?
Thanks in advance.
I tried creating httpcontextwrapper class in .NET 8 inheriting System.Web so that wrapper class is used to convert context to System.Web
This approach didn’t work.
tony is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.