CodeLiturgy.Dashboard/CodeLiturgy.Data.Auth/Users/SessionExtensions.cs

18 lines
514 B
C#
Raw Normal View History

2022-09-29 02:37:24 +03:00
using System.Text.Json;
using Microsoft.AspNetCore.Http;
namespace BlueWest.WebApi.Session;
public static class SessionExtensions
{
public static void Set<T>(this ISession session, string key, T value) where T: class
{
session.SetString(key, JsonSerializer.Serialize(value));
}
public static T Get<T>(this ISession session, string key) where T: class
{
var value = session.GetString(key);
return value == null ? default : JsonSerializer.Deserialize<T>(value);
}
}