Ejemplo n.º 1
0
        public override Task OnConnected()
        {
            //string guid = Guid.NewGuid().ToString().Replace("-", string.Empty);
            string guid = "1234567890";
            //生成cookie
            HttpCookie cookie = new HttpCookie("qrcodeguid");

            cookie.Value    = guid;
            cookie.Expires  = DateTime.Now.AddMinutes(10);
            cookie.HttpOnly = true;
            //将cookie写到浏览器
            HttpContext.Current.Response.Cookies.Add(cookie);

            //将连接标志和二维码标志关联起来
            redis.Set(guid, Context.ConnectionId, new TimeSpan(0, 10, 0));
            redis.Set(Context.ConnectionId, guid, new TimeSpan(0, 10, 0));

            return(base.OnConnected());
        }
Ejemplo n.º 2
0
        public string SetStr(string key, string value)
        {
            string result = "";

            try
            {
                DoRedisString rs     = new DoRedisString();
                bool          isTrue = rs.Set(key, value, DateTime.Now.AddMinutes(2));
                result = isTrue ? "success" : "error";
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }
            return(result);
        }