Beispiel #1
0
        /// <summary>
        /// 添加缓存
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="key">key</param>
        /// <param name="obj">对象</param>
        /// <param name="type"></param>
        /// <param name="num"></param>
        public static void Add <T>(string key, T obj, DateTimeType type, int num) where T : class
        {
            if (obj == null)
            {
                return;
            }
            DateTime dt = DateTimeTypeHelper.GetDateTime(type, num);

            HttpRuntime.Cache.Insert(key, obj, null, dt, TimeSpan.Zero);
        }
Beispiel #2
0
        /// <summary>
        /// 添加Cookie
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        public static void Add <T>(CookieEntity <T> entity) where T : class
        {
            HttpCookie cookie = new HttpCookie(entity.CookieName);
            string     v      = typeof(T) == typeof(string) ? entity.Value.ToString() : JsonHelper.ToJson(entity.Value);

            if (entity.IsEncryp)
            {
                v = EncryptHelper.Encrypt(entity.EncrypKey, v);
            }
            if (entity.IsEncode)
            {
                v = HttpUtility.UrlEncode(v, entity.Encoding);
            }
            cookie.Value   = v;
            cookie.Path    = entity.Path;
            cookie.Domain  = entity.Domain;
            cookie.Expires = DateTimeTypeHelper.GetDateTime(entity.Type, entity.Number);
            HttpContext.Current.Response.Cookies.Add(cookie);
        }