Esempio n. 1
0
        /// <summary>
        /// 保存Cookie
        /// </summary>
        /// <typeparam name="T">需要存放的Cookie值的类型</typeparam>
        /// <param name="nodeName">配置的Cookie节点名,若未配置,则使用此名作为cookie存储名且使用默认配置</param>
        /// <param name="obj">需要存放的Cookie值</param>
        public static void SaveCookie <T>(string nodeName, T obj)
        {
            string persistType;
            string securityLevel;
            Dictionary <string, string> parameters;

            LoadConfig(nodeName, out persistType, out securityLevel, out parameters);

            ICookiePersist    persister   = CreatePersister(persistType);
            ICookieEncryption safer       = CreateCookieHelper(securityLevel);
            string            cookieValue = safer.EncryptCookie <T>(obj, parameters);

            persister.Save(GetCookieName(nodeName, parameters), cookieValue, parameters);
        }
Esempio n. 2
0
        public static void Set <T>(string nodeName, T obj, int?expiredMinutes = null)
        {
            string persistType;
            string securityLevel;
            Dictionary <string, string> parameters;

            LoadConfig(nodeName, out persistType, out securityLevel, out parameters);

            if (expiredMinutes.HasValue)
            {
                parameters["expires"] = expiredMinutes.Value.ToString();
            }

            ICookiePersist    persister   = CreatePersister(persistType);
            ICookieEncryption safer       = CreateCookieHelper(securityLevel);
            string            cookieValue = safer.EncryptCookie <T>(obj, parameters);

            persister.Save(GetCookieName(nodeName, parameters), cookieValue, parameters);
        }