You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
544 B
19 lines
544 B
using Microsoft.AspNetCore.Http;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Infrastructure.Extensions
|
|
{
|
|
public static class SessionExtensions
|
|
{
|
|
public static void Set<T>(this ISession session, string key, T value)
|
|
{
|
|
session.SetString(key, JsonConvert.SerializeObject(value));
|
|
}
|
|
|
|
public static T Get<T>(this ISession session, string key)
|
|
{
|
|
var value = session.GetString(key);
|
|
return value == null ? default(T) : JsonConvert.DeserializeObject<T>(value);
|
|
}
|
|
}
|
|
} |