You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWebMobileService/Common/SessionUtil.cs

201 lines
5.0 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**********************************************
* 作 者: 办公协同
* 创建日期: 2008.12.30
* 描 述: Session管理类
* 修改日期: 2009.01.10
* 版 本: 0.5.0
***********************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Web.SessionState;
using System.Web;
using System.Configuration;
namespace DSWebMobileService.Common
{
/// <summary>
/// 类名SessionUtil
/// 描述提供与Session相关的一些方法
///
/// 作者:办公协同
/// 创建时间2008/12/30
/// 最后修改时间2008/12/30
/// </summary>
///
public class SessionUtil : IDictionary, ICollection
{
private static SessionUtil _SessionUtil;
/// <summary>
/// 获得Session
/// </summary>
public static SessionUtil Session
{
get
{
if (_SessionUtil == null)
{
_SessionUtil = new SessionUtil();
}
return _SessionUtil;
}
}
//private HttpSessionState _Session;
//private SessionUtil()
//{
// _Session = HttpContext.Current.Session;
//}
private HttpSessionState _Session
{
get { return HttpContext.Current.Session; }
}
IDictionaryEnumerator IDictionary.GetEnumerator()
{
throw new NotImplementedException();
}
/// <summary>
/// 获取存储在会话状态集合中所有值的键的集合。
/// </summary>
public ICollection Keys
{
get { return _Session.Keys; }
}
/// <summary>
/// 返回一个枚举数,可用来读取当前会话中所有会话状态的变量名称。
/// </summary>
public IEnumerator GetEnumerator()
{
return _Session.GetEnumerator();
}
/// <summary>
/// 判断Session中是否包含了给定的key。
/// </summary>
public bool Contains(object key)
{
return _Session[(String)key] != null;
}
/// <summary>
/// 向会话状态集合添加一个新项。
/// </summary>
public void Add(object key, object value)
{
_Session.Add((String)key, value);
}
/// <summary>
/// 从会话状态集合中移除所有的键和值。
/// </summary>
public void Clear()
{
_Session.Clear();
}
/// <summary>
/// 获取并设置在会话状态提供程序终止会话之前各请求之间所允许的时间(以分钟为单位)。
/// </summary>
public int TimeOut
{
get { return _Session.Timeout; }
set { _Session.Timeout = value; }
}
public void CopyTo(Array array, int index)
{
throw new NotImplementedException();
}
/// <summary>
/// 获取会话状态集合中的项数。
/// </summary>
public int Count
{
get { return _Session.Count; }
}
/// <summary>
/// 获取一个对象,该对象可用于同步对会话状态值的集合的访问。
/// </summary>
public object SyncRoot
{
get { return _Session.SyncRoot; }
}
/// <summary>
/// 获取一个值,该值指示对会话状态值的集合的访问是否是同步(线程安全)的。
/// </summary>
public bool IsSynchronized
{
get { return _Session.IsSynchronized; }
}
/// <summary>
/// 删除会话状态集合中的项。
/// </summary>
public void Remove(object key)
{
_Session.Remove((String)key);
}
/// <summary>
/// 从会话状态集合中移除所有的键和值。
/// </summary>
public void RemoveAll()
{
_Session.RemoveAll();
}
/// <summary>
/// 取消当前会话。
/// </summary>
public void Abandon()
{
_Session.Abandon();
}
public ICollection Values
{
get { throw new NotImplementedException(); }
}
/// <summary>
/// 获取一个值,该值指示会话是否为只读。
/// </summary>
public bool IsReadOnly
{
get { return _Session.IsReadOnly; }
}
/// <summary>
/// 获取一个值,该值指示会话是否为固定大小的。
/// </summary>
public bool IsFixedSize
{
get { return false; }
}
public object this[object key]
{
get { return _Session[(String)key]; }
set
{
_Session[(String)key] = value;
}
}
}
}