Session对象处理
public class ObjSession
{
/// <summary>
/// 创建一个Session对象
/// </summary>
/// <param name="Key">键名</param>
/// <param name="Value">键值</param>
/// <param name="Time">保存时间(分钟为单位)</param>
/// <returns></returns>
public static bool Add(string Key, string Value, int Time)
{
try
{
HttpContext.Current.Session[Key] = Value;
HttpContext.Current.Session.Timeout = Time;
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 获取一个Session对象
/// </summary>
/// <param name="Key">键名</param>
/// <returns></returns>
public static object Value(string Key)
{
return HttpContext.Current.Session[Key];
}
/// <summary>
/// 判断一个Session对象是否存在
/// </summary>
/// <param name="Key">键名</param>
/// <returns></returns>
public static bool Exis(string Key)
{
try
{
if (HttpContext.Current.Session[Key] != null & HttpContext.Current.Session[Key].ToString() != "")
{
return true;
}
return false;
}
catch
{
return false;
}
}
/// <summary>
/// 删除一个Session对象
/// </summary>
/// <param name="Key">键名</param>
public static void Remove(string Key)
{
try
{
HttpContext.Current.Session.Remove(Key);
}
catch
{ }
}
}

浙公网安备 33010602011771号