Null Cookies Collection

Aug 4, 2011 at 6:46 PM

I've been working to get the sample project up and running (and create my own) and am having troubles receiving cookies on the server.  I see in the included sample project SuperWebSocketWeb, the default.aspx page appends a cookie named 'name' and then on server connect (within Global.asax) you try to read session.Cookies["name"].  In this context, the property session.Cookies is always empty.

I did however create a sample forms project where I am able to specify the cookie named 'name' like :

var cookies = new List<KeyValuePair<string, string>>();
cookies.Add(new KeyValuePair<string, string>("name", this.tbName.Text));
            
this._socketClient = new WebSocket(this.tbServerAddress.Text, "basic", cookies);

When registering from desktop in this manner, the cookie is available within the NewSessionConnected event.  I'm pretty new to all this, so it's entirely possible I'm missing something simple - but any guidance would be greatly appreciated - I need my cookies! :)

Thanks,

Matt Klinker

Aug 5, 2011 at 6:30 PM

I went ahead and dug a bit deeper and found that I was actually sending duplicate cookies, and the code within WebSocketSession.cs was not handling this case.  I confirmed the fix by adding a check to the SetCookies method as follows:

if (!cookies.ContainsKey(key))
    cookies.Add(key, Uri.UnescapeDataString(value));

And also can confirm that code as is worked just fine once I cleared out my local cookies.  I realize that it's not good to have multiple cookie names (in this case it was actually Google Analytics that were duplicated); but from what I gather from this discussion on SO: http://stackoverflow.com/questions/4056306/how-to-handle-multiple-cookies-with-the-same-name it's definitely a real possibility and I think the session should handle this a bit more gracefully.

Thanks for the great project, appreciate all the hard work that must've gone into this.

Matt Klinker

Coordinator
Aug 6, 2011 at 12:23 AM

OK, I'll enhance it!

Coordinator
Sep 11, 2011 at 11:08 AM

I have fixed this issue in this change on my way:

http://superwebsocket.codeplex.com/SourceControl/changeset/changes/69817

Sep 13, 2011 at 1:46 AM

I cleared my cookies but I still have the same problem. When I set a cookie, its not being passed to the web socket connection. It works perfectly in the sample project but not in mine. I am setting the cookie through a web service call. I will check and see if that makes a difference to setting the cookie using a web forms postback.

Sep 13, 2011 at 1:59 AM

I figured out my own problem. Sorry about that. I had hard coded the address to localhost, rather than 127.0.0.1. They both respond fine but I set my cookies ont he 127.0.0.1. I did not set my cookies on localhost. Once I changed the WS connect string to 127.0.0.1. I can see that I have cookie access now. Very good!