using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
namespace CP.Common
{
public static class SessionUtil
{
///
/// 添加Session,调动有效期为20分钟
///
/// Session对象名称
/// Session值
public static void Insert(string strSessionName, string strValue)
{
HttpContext.Current.Session[strSessionName] = strValue;
HttpContext.Current.Session.Timeout = 20;
}
///
/// 添加Session,调动有效期为20分钟
///
/// Session对象名称
/// Session值数组
public static void Inserts(string strSessionName, string[] strValues)
{
HttpContext.Current.Session[strSessionName] = strValues;
HttpContext.Current.Session.Timeout = 20;
}
///
/// 添加Session
///
/// Session对象名称
/// Session值
/// 调动有效期(分钟)
public static void Insert(string strSessionName, string strValue, int iExpires)
{
HttpContext.Current.Session[strSessionName] = strValue;
HttpContext.Current.Session.Timeout = iExpires;
}
///
/// 添加Session
///
/// Session对象名称
/// Session值数组
/// 调动有效期(分钟)
public static void Inserts(string strSessionName, string[] strValues, int iExpires)
{
HttpContext.Current.Session[strSessionName] = strValues;
HttpContext.Current.Session.Timeout = iExpires;
}
///
/// 读取某个Session对象值
///
/// Session对象名称
/// Session对象值
public static string Read(string strSessionName)
{
if (HttpContext.Current.Session[strSessionName] == null)
{
return null;
}
else
{
return HttpContext.Current.Session[strSessionName].ToString();
}
}
///
/// 读取某个Session对象值数组
///
/// Session对象名称
/// Session对象值数组
public static string[] Reades(string strSessionName)
{
if (HttpContext.Current.Session[strSessionName] == null)
{
return null;
}
else
{
return (string[])HttpContext.Current.Session[strSessionName];
}
}
///
/// 删除某个Session对象
///
/// Session对象名称
public static void Remove(string strSessionName)
{
HttpContext.Current.Session[strSessionName] = null;
}
}
}