Exemplo n.º 1
0
        /// <summary>
        /// 更新 Cookie
        /// </summary>
        /// <param name="id">id</param>
        /// <param name="openId">openId</param>
        /// <param name="passwordkey">密钥</param>
        /// <param name="minutes">保存时间,单位:分</param>
        public void UpdateCookie(Guid id, string openId, string passwordkey, int minutes)
        {
            string ip = IpHelper.UserHostAddress;

            if (ip == "0.0.0.0")
            {
                return;
            }

            HttpCookie user = HttpContext.Current.Request.Cookies[CookieUserName];

            if (user == null)
            {
                CreateCookie(id, openId, passwordkey, minutes);
                return;
            }

            user.Value = StrCrypt.EncryptDes(string.Format("{0}|{1}", id, StrCrypt.EncryptDes(openId, passwordkey)), ip);

            if (minutes > 0)
            {
                user.Expires = DateTime.Now.AddMinutes(minutes);
            }

            HttpContext.Current.Response.Cookies.Set(user);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 创建Admin Cookie
        /// </summary>
        /// <param name="id">id</param>
        /// <param name="password">密码</param>
        /// <param name="passwordKey">密钥</param>
        /// <param name="safeCode">安全码</param>
        public void CreateAdminCookie(Guid id, string password, string passwordKey, string safeCode)
        {
            string ip = IpHelper.UserHostAddress;

            FormsAuthentication.SetAuthCookie(StrCrypt.EncryptDes(string.Format("{0}|{1}|{2}|{3}", id, StrCrypt.EncryptDes(password, passwordKey), safeCode, IpHelper.UserHostAddress), ip), false);
        }