Esempio n. 1
0
        public bool RemoveCookies()
        {
            bool flag = false;

            try
            {
                //删除所有的Cookies数据
                int    limit      = System.Web.HttpContext.Current.Request.Cookies.Count;
                string cookieName = "";
                for (int i = 0; i < limit; i++)
                {
                    cookieName = System.Web.HttpContext.Current.Request.Cookies[i].Name;
                    if (cookieName == "rebate_user" || cookieName == "YmCps_user")
                    {
                        continue;
                    }

                    CookUtils.RemoveCookie(cookieName);
                }
                flag = true;
            }
            catch (Exception ex)
            {
                LogService.logDebug(ex);
            }
            return(flag);
        }
Esempio n. 2
0
        /// <summary>
        /// 设置Cookies
        /// </summary>
        /// <param name="CookiesName">Cookies名称</param>
        /// <param name="_strCookiesParm">Cookies键值</param>
        /// <returns></returns>
        private bool SetCookiesKeyValue(string CookiesName, Dictionary <string, string> CookiesParm)
        {
            bool flag = false;

            try
            {
                if (String.IsNullOrEmpty(CookiesName) || CookiesParm == null || CookiesParm.Count < 1)
                {
                    return(false);
                }

                if (this.ExpiresTime < 1)
                {
                    this.ExpiresTime = DefaultExpiresTime;
                }

                CookUtils.AddCookie(CookiesName, CookiesParm, DateTime.Now.AddHours(ExpiresTime));
                flag = true;
            }
            catch (Exception ex)
            {
                LogService.logDebug(ex);
            }
            return(flag);
        }
Esempio n. 3
0
        /// <summary>
        /// 设置Cookies
        /// </summary>
        /// <param name="CookiesName">Cookies名称</param>
        /// <param name="CookiesValue">Cookies值</param>
        /// <returns></returns>
        private bool SetCookiesValue(string CookiesName, string CookiesValue)
        {
            bool flag = false;

            try
            {
                //过滤特殊字符
                CookiesValue = CookiesValue.Replace("\r", "").Replace("\n", "").Replace("%0d%0a", "");
                if (String.IsNullOrEmpty(CookiesName) || String.IsNullOrEmpty(CookiesValue))
                {
                    return(false);
                }

                if (this.ExpiresTime < 1)
                {
                    this.ExpiresTime = DefaultExpiresTime;
                }

                CookUtils.AddCookie(CookiesName, CookiesValue, DateTime.Now.AddHours(ExpiresTime));
                flag = true;
            }
            catch (Exception ex)
            {
                Log.LogService.logDebug(ex);
            }
            return(flag);
        }
Esempio n. 4
0
        /// <summary>
        /// 获取Cookies
        /// </summary>
        /// <param name="CookiesName">Cookies名称</param>
        /// <param name="CookiesKeyName">Cookies子名称</param>
        /// <returns></returns>
        public string GetCookies(string CookiesName, string CookiesKeyName = null)
        {
            string strCookValue = "";

            try
            {
                if (!String.IsNullOrEmpty(CookiesName) && !String.IsNullOrEmpty(CookiesKeyName))
                {
                    return(CookUtils.GetCookieValue(CookiesName, CookiesKeyName));
                }
                else if (!String.IsNullOrEmpty(CookiesName))
                {
                    return(CookUtils.GetCookieValue(CookiesName));
                }
            }
            catch (Exception ex)
            {
                Log.LogService.logDebug(ex);
            }
            return(strCookValue);
        }