Skip to content

Instantly share code, notes, and snippets.

@motowilliams
Created October 23, 2011 18:30
Show Gist options
  • Save motowilliams/1307681 to your computer and use it in GitHub Desktop.
Save motowilliams/1307681 to your computer and use it in GitHub Desktop.
Asp-net-MVC-Session-State-Extension-Method
public static class SessionStateExtensions
{
public static void Put<T>(this HttpSessionStateBase httpSession, T value) where T : class
{
httpSession[typeof (T).FullName] = value;
}
public static void Put<T>(this HttpSessionStateBase httpSession, string key, T value) where T : class
{
httpSession[typeof (T).FullName + key] = value;
}
public static T Get<T>(this HttpSessionStateBase httpSession) where T : class
{
var o = (T) httpSession[typeof (T).FullName];
return o == null ? null : o;
}
public static T Get<T>(this HttpSessionStateBase httpSession, string key) where T : class
{
var o = (T) httpSession[typeof (T).FullName + key];
return o == null ? null : o;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment