c# Session操作类
public class SessionHelper
{
/// <summary>
/// 添加一个Session
/// </summary>
/// <param name="sessionName"></param>
/// <param name="sessionVal"></param>
public static void Add(string sessionName, object sessionVal)
{
HttpContext.Current.Session[sessionName] = sessionVal;
}
/// <summary>
/// 添加一个Session 并设置过期时间
/// </summary>
/// <param name="sessionName"></param>
/// <param name="sessionVal"></param>
/// <param name="expires"></param>
public static void Add(string sessionName, object sessionVal, int expires)
{
HttpContext.Current.Session[sessionName] = sessionVal;
HttpContext.Current.Session.Timeout = expires;
}
/// <summary>
/// 获取Session
/// </summary>
/// <param name="sessionName"></param>
/// <returns></returns>
public static object Get(string sessionName)
{
if (HttpContext.Current.Session[sessionName] == null)
{
return null;
}
else
{
return HttpContext.Current.Session[sessionName];
}
}
/// <summary>
/// 删除Session
/// </summary>
/// <param name="sessionName"></param>
public static void Del(string sessionName)
{
HttpContext.Current.Session[sessionName] = null;
}
}