咨询电话:186 7916 6165 咨询电话:186 7916 6165 (微信同号)    在线QQ:181796286
NEWS BLOG ·
学无止境
关注开优网络 关注前沿
ASP.NET公共类库之分页类PageListUtil.cs
ASP.NET公共类库之Smtp邮件辅助类SmtpMail.cs

ASP.NET公共类库之Session封装SessionAdapter.cs

发表日期:2015-09-06    文章编辑:南昌开优网络    浏览次数:3457    标签:ASP.NET应用

/**********************************************
 * 类作用:   Session封装
 * 作者:开优网络
 * http://www.kaiu.net
 ***********************************************/

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Web.SessionState;
using System.Web;

namespace Svnhost.Common
{
    /// <summary>
    /// 类名:SessionAdapter
    /// 功能描述:Session封装	
    public class SessionAdapter : MarshalByRefObject, IDictionary
    {
        private HttpSessionState _session;  private static SessionAdapter _SessionAdapter;

        public static SessionAdapter Session
        {
            get
            {
                if (_SessionAdapter == null)
                {
                    _SessionAdapter= new SessionAdapter();
                }
                return _SessionAdapter;
            }
        }

      
        private SessionAdapter()
        {
            _session = HttpContext.Current.Session;
        }

      
        IDictionaryEnumerator IDictionary.GetEnumerator()
        {
            throw new NotImplementedException();
        }

     
        public ICollection Keys
        {
            get { return _session.Keys; }
        }

      
        public void CopyTo(Array array, int index)
        {
            throw new NotImplementedException();
        }

    
        public int Count
        {
            get { return _session.Count; }
        }

      
        public object SyncRoot
        {
            get { return _session.SyncRoot; }
        }

     
        public bool IsSynchronized
        {
            get { return _session.IsSynchronized; }
        }

   
        public IEnumerator GetEnumerator()
        {
            return _session.GetEnumerator();
        }

     
        public bool Contains(object key)
        {
            return _session[(String)key] != null;
        }

     
        public void Add(object key, object value)
        {
            _session.Add((String)key, value);
        }

     
        public void Clear()
        {
            _session.Clear();
        }

    
        public void Remove(object key)
        {
            _session.Remove((String)key);
        }

       
        public ICollection Values
        {
            get { throw new NotImplementedException(); }
        }

        
        public bool IsReadOnly
        {
            get { return _session.IsReadOnly; }
        }

      
        public bool IsFixedSize
        {
            get { return false; }
        }

      
        public object this[object key]
        {
            get { return _session[(String)key]; }
            set
            {
                _session[(String)key] = value;
            }
        }
    }
}