How do I read multivalued cookies in SignalR?
How can multivalued cookies be read in SignalR Hub?
For example: I have a cookie that is stored as
var myCookie = new NameValueCollection();
myCookie.Add("IdOne", "Value1");
myCookie.Add("IdTwo", "Value2");
var webDummyCookie = new CookieHeaderValue("dummyCookie", myCookie);
response.Headers.AddCookies(new CookieHeaderValue[] { webDummyCookie });
How can I get the values for IdOne and IdTwo separately?
All I can do with SignalR is:
Cookie cookie; //Microsoft.AspNet.SignalR.Cookie
var cookies = Context.Request.Cookies;
if (cookies.TryGetValue(dummyCookie, out cookie) && cookie.Value != null)
{
var receivedCookie = cookie.Value; //Here is the problem, as I can't do .Values[<key>]
}
Does anyone know how to do this?
+3
source to share
1 answer
Although the question is too old. Hope this helps others.
I am using SignalR 2.2.1.0 and here is the solution:
var httpContext = Context.Request.GetHttpContext();
var dummyCookie= httpContext.Request.Cookies["dummyCookie"];
if(dummyCookie != null)
{
var receivedCookie = dummyCookie["IdOne"]; // result
}
+1
source to share