SignalR中获取cookie的解决方法

时间:2021-12-15 00:13:23

普通类中: 
            HttpCookie cookie = new HttpCookie(CookieKeyCometUserName);            cookie.Name = CookieKeyCometUserName;            cookie.Value = userName;            cookie.Expires = SystemTime.Now().AddDays(1);   // 不加这句,就读不到,不知何故?            HttpContext.Current.Response.Cookies.Add(cookie);
 
Hub方法中:
            HttpCookie cookie = HttpContext.Current.Request.Cookies[CookieKeyCometUserName];            if (cookie != null)            {                return cookie.Value.DESDecrypt();            }            return "";