2

I need to set session variable in .NET Standard project and also get the value from same as well as .NET framework project. I am not able to see Httpcontext in .NET Standard. Also, I could not find any ways to use session in .net standard project.

How do I set session variable value in .NET Standard project and get its value in .NET Standard and .NETFramework project???

I found this URL: HttpContext in .net standard library Tried using Microsoft.AspNetCore.Http.Abstractions but session only accepts byte[] type.

CodesDDecodes
  • 132
  • 1
  • 15

1 Answers1

0

A library for business logic directly accessing session state is no good architecture. Business logic code should not even care whether it runs in a web application or some other type of application.

Create a better abstraction. Declare an interface ISession in your library with all the methods that you want to use. Then provide a mechanism for an application that uses your library to provide an actual implementation of ISession.

In your web application, write a class that implements ISession by using the ASP.net session concept in the .net Framework.

NineBerry
  • 26,306
  • 3
  • 62
  • 93