Skip to content

Instantly share code, notes, and snippets.

@RyanABailey
Last active August 29, 2015 13:57
Show Gist options
  • Save RyanABailey/9656405 to your computer and use it in GitHub Desktop.
Save RyanABailey/9656405 to your computer and use it in GitHub Desktop.
public class SessionWrapper
{
private static HttpSessionState Session
{
get
{
if (HttpContext.Current == null)
{
throw new ApplicationException("No Http Context, No Session to Get!");
}
return HttpContext.Current.Session;
}
}
public static T Get<T>(string key)
{
if (Session[key] == null)
{
return default(T);
}
else
{
return (T)Session[key];
}
}
public static void Set<T>(string key, T value)
{
Session[key] = value;
}
public static void Remove<T>(string key)
{
if (Session[key] != null)
{
Session.Remove(key);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment