Beispiel #1
0
 /// <summary>
 /// 读cookie值
 /// </summary>
 /// <param name="strName">名称</param>
 /// <returns>cookie值</returns>
 public static string GetCookie(string strName, bool isEncrypt)
 {
     if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies[strName] != null)
     {
         if (isEncrypt)
         {
             return(AESEncryptHelper.Decrypt(HttpContext.Current.Request.Cookies[strName].Value.ToString()));
         }
         else
         {
             return(HttpContext.Current.Request.Cookies[strName].Value.ToString());
         }
     }
     return("");
 }
Beispiel #2
0
        /// <summary>
        /// 写cookie值
        /// </summary>
        /// <param name="strName">名称</param>
        /// <param name="strValue">值</param>
        public static void WriteCookie(string strName, string strValue, bool isEncrypt)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[strName];

            if (cookie == null)
            {
                cookie = new HttpCookie(strName);
            }
            if (isEncrypt)
            {
                cookie.Value = AESEncryptHelper.Encrypt(strValue);
            }
            else
            {
                cookie.Value = strValue;
            }
            HttpContext.Current.Response.AppendCookie(cookie);
        }
Beispiel #3
0
        /// <summary>
        /// 写cookie值
        /// </summary>
        /// <param name="strName">名称</param>
        /// <param name="strValue">值</param>
        /// <param name="strValue">过期时间(分钟)</param>
        public static void WriteCookie(string strName, string strValue, int expires, bool isEncrypt)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[strName];

            if (cookie == null)
            {
                cookie = new HttpCookie(strName);
            }
            if (isEncrypt)
            {
                cookie.Value = AESEncryptHelper.Encrypt(strValue);
            }
            else
            {
                cookie.Value = strValue;
            }
            if (expires != 0)
            {
                cookie.Expires = DateTime.Now.AddMinutes(expires);
            }
            HttpContext.Current.Response.AppendCookie(cookie);
        }