Exemplo n.º 1
0
        /// <summary>
        /// 从Session获取对象
        /// </summary>
        /// <typeparam name="T">对象的类型</typeparam>
        /// <param name="key">Session KEY</param>
        /// <returns></returns>
        protected virtual T GetObjectFromSession <T>(string key) where T : class
        {
            var objBytes = HttpContext.Session.Get(key);

            if (objBytes != null && objBytes.Length != 0)
            {
                try
                {
                    T obj = ObjectUtils.BytesToObject(objBytes) as T;
                    return(obj);
                }
                catch (System.Runtime.Serialization.SerializationException)
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }