Last active
August 29, 2015 13:57
-
-
Save RyanABailey/9656405 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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