Reputation: 1921
I'm trying to migrate an ASP.NET MVC site to ASP.NET Core with the .NET Core runtime. Previously we could get objects out of the session store, even in different assemblies, with
var obj = HttpContext.Current.Session[key]
Now I've read we must inject IHttpContextAccessor and use the method on _contextAccessor.HttpContext.Session. But the methods of the Session object have changed, and it no longer has indexing applied.
I have seen people in other questions using HttpContext.Session.GetString() and HttpContext.Session.SetString():
With these I could at least de/serialize the object I want to fetch/get. But I can't find these methods on the interface.
'ISession' does not contain a definition for 'GetString' and no extension method 'GetString' accepting a first argument of type 'ISession' could be found
How to I get access to these methods?
Upvotes: 18
Views: 13969
Reputation: 118947
GetString
is an extension method in the Microsoft.AspNetCore.Http.Extensions
assembly, make sure you have a reference to that. You may also need to import it:
using Microsoft.AspNetCore.Http;
Upvotes: 42