2021-11-07 22:06:16 +00:00
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
namespace EFB.Sessions
|
|
|
|
{
|
|
|
|
public static class SessionExtensions
|
|
|
|
{
|
|
|
|
public static void SetObject(this ISession session, string key, object value)
|
|
|
|
{//Sets the object of a session to Object
|
2022-02-28 21:53:28 +00:00
|
|
|
session.SetString(key, JsonConvert.SerializeObject(value, Formatting.None,
|
|
|
|
new JsonSerializerSettings()
|
|
|
|
{
|
2022-01-27 09:46:38 +00:00
|
|
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
|
|
|
}
|
|
|
|
));
|
2021-11-07 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static T GetObject<T>(this ISession session, string key)
|
|
|
|
{//Gets a session of known type (T)
|
|
|
|
var value = session.GetString(key);
|
|
|
|
return value == null ? default(T) : JsonConvert.DeserializeObject<T>(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|