Skip to content

Instantly share code, notes, and snippets.

@ccccccmd
Created August 15, 2018 06:16
Show Gist options
  • Select an option

  • Save ccccccmd/a1ca2b266b5c756d42fc565c0f2c6dd5 to your computer and use it in GitHub Desktop.

Select an option

Save ccccccmd/a1ca2b266b5c756d42fc565c0f2c6dd5 to your computer and use it in GitHub Desktop.
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment