Reputation: 2437
i use the .net core "Microsoft.AspNetCore.Session": "1.0.0"
to use the session in my .net core project and use the extension method witch is mention on MSDN its like this
public static void Set<T>(this ISession session, string key, T value)
{
session.SetString(key, JsonConvert.SerializeObject(value));
}
In my controller
HttpContext.Session.Set<BLL.clsPolicy>("PolicyDATAAPI", policyObj);
when i pass the object to session this doing the serialization it make the some problems in my object class like : private variables are not serialize like that ,
any way to store object store in session without serialize ? ?
Upvotes: 0
Views: 1187
Reputation: 33851
Out of the box, in .Net Core, there is no way to store an object in session without serializing it. If you want to add session support for an in memory object store you'd need to implement it.
To implement it you'd need to implement your own implementation of ISession
and ISessionStore
and register them with the DI container. Then you'd need to add extension methods to ISession
to support a Set
method that takes a key and an object as parameters. Internally in your implementation of ISession you could use a thread safe dictionary to store the objects.
But again, out of the box, .Net Core dos not provide support for storing non-serialized objects in memory. If you want it, you'd have to write it.
Upvotes: 2