IHttpContextAccessor Session GetString

I am trying to migrate an ASP.NET MVC site to ASP.NET Core using the .NET Core runtime. Previously, we could get objects from the session store even in different assemblies using

var obj = HttpContext.Current.Session[key]

      

Now I have read, we have to inject the IHttpContextAccessor and use the method on the _contextAccessor.HttpContext.Session. But the methods of the Session object changed and it no longer applied indexing.

I've seen people on other questions using HttpContext.Session.GetString () and HttpContext.Session.SetString ():

Accessing HttpContext.Current

With this, I could at least de-serialize the object I want to get / get. But I cannot find these methods on the interface.

"ISession" does not contain a definition for "GetString" and no extension method "GetString" that takes a first argument of type "ISession" can be found

How do I access these methods?

+3


source to share


1 answer


GetString

is an extension method in an assembly Microsoft.AspNetCore.Http.Extensions

, make sure you have a reference to that. You may also need to import it:



using Microsoft.AspNetCore.Http;

      

+9


source







All Articles