コード例 #1
0
 /// <summary>读取Cookie某个对象的Value值,返回Value值,如果对象本就不存在,则返回null
 /// </summary>
 /// <param name="CookiesName">Cookie对象名称</param>
 /// <returns>返回对象的Value值,返回Value值,如果对象本就不存在,则返回null</returns>
 public static string GetCookies(string CookiesName)
 {
     if (HttpContext.Current.Request.Cookies[CookiesName] == null)
     {
         return(null);
     }
     else
     {
         return(Encrypt_.DESEncrypt(HttpContext.Current.Request.Cookies[CookiesName].Value));
     }
 }
コード例 #2
0
        /// <summary>创建COOKIE对象并赋Value值
        /// </summary>
        /// <param name="CookiesName">COOKIE对象名</param>
        /// <param name="IExpires">COOKIE对象有效时间(秒数),1表示永久有效,0和负数都表示不设有效时间,大于等于2表示具体有效秒数,31536000秒=1年=(60*60*24*365),</param>
        /// <param name="CookiesValue">COOKIE对象Value值</param>
        public static void WriteCookies(string CookiesName, int IExpires, string CookiesValue)
        {
            HttpCookie objCookie = new HttpCookie(CookiesName.Trim());

            objCookie.Value = Encrypt_.DESEncrypt(CookiesValue.Trim());    //加密存储
            if (IExpires > 0)
            {
                if (IExpires == 1)
                {
                    objCookie.Expires = DateTime.MaxValue;
                }
                else
                {
                    objCookie.Expires = DateTime.Now.AddMinutes(IExpires);
                }
            }
            HttpContext.Current.Response.Cookies.Add(objCookie);
        }
コード例 #3
0
 /// <summary>读取Cookie某个对象的Value值,返回Value值,如果对象本就不存在,则返回null
 /// </summary>
 /// <param name="CookiesName">Cookie对象名称</param>
 /// <param name="KeyName">键值</param>
 /// <returns>返回对象的Value值,返回Value值,如果对象本就不存在,则返回null</returns>
 public static string GetCookies(string CookiesName, string KeyName)
 {
     if (HttpContext.Current.Request.Cookies[CookiesName] == null)
     {
         return(null);
     }
     else
     {
         string strObjValue = Encrypt_.DESEncrypt(HttpContext.Current.Request.Cookies[CookiesName].Value);
         string strKeyName2 = KeyName + "=";
         if (strObjValue.IndexOf(strKeyName2) == -1)
         {
             return(null);
         }
         else
         {
             return(Encrypt_.DESEncrypt(HttpContext.Current.Request.Cookies[CookiesName][KeyName]));
         }
     }
 }
コード例 #4
0
        /// <summary>创建COOKIE对象并赋多个KEY键值
        /// 设键/值如下:
        /// NameValueCollection myCol = new NameValueCollection();
        /// myCol.Add("red", "rojo");
        /// myCol.Add("green", "verde");
        /// myCol.Add("blue", "azul");
        /// myCol.Add("red", "rouge");   结果“red:rojo,rouge;green:verde;blue:azul”
        /// </summary>
        /// <param name="CookiesName">COOKIE对象名</param>
        /// <param name="IExpires">COOKIE对象有效时间(秒数),1表示永久有效,0和负数都表示不设有效时间,大于等于2表示具体有效秒数,31536000秒=1年=(60*60*24*365),</param>
        /// <param name="CookiesKeyValueCollection">键/值对集合</param>
        public static void WriteCookies(string CookiesName, int IExpires, NameValueCollection CookiesKeyValueCollection)
        {
            HttpCookie objCookie = new HttpCookie(CookiesName.Trim());

            foreach (String key in CookiesKeyValueCollection.AllKeys)
            {
                objCookie[key] = Encrypt_.DESEncrypt(CookiesKeyValueCollection[key].Trim());
            }
            if (IExpires > 0)
            {
                if (IExpires == 1)
                {
                    objCookie.Expires = DateTime.MaxValue;
                }
                else
                {
                    objCookie.Expires = DateTime.Now.AddSeconds(IExpires);
                }
            }
            HttpContext.Current.Response.Cookies.Add(objCookie);
        }