Reputation: 85
I'm trying to implement instant messaging using Signalr in a ASP.NET webforms site.
I have made a good start so far, I can send a message from one client to another without any issue.
My problem comes from maintaining chat windows across asp.net requests.
When a user has a chat window open and navigates to a new page on the site, this counts as a disconnect and new connect to the signalr hub. (Client gets new ConnectionID).
This is a problem as it means I cannot determine weather this is a users first connect (no chat window open, just logged into site) or if they had an active chat window and just changed page.
If they just changed page I would like to keep the chat window open with messages showing. I can reconstruct the conversation from our database, but have no way to know if this conversation should be shown or not.
I have considered using some sort of timeout mechanism (if this conversation was active within the last X minutes, then show it on new page) but this seems to me to be a bit unwieldy.
As I can't save the active conversations in OnDisconnect (as this cannot take any arguments) I would have to use some sort of polling mechanism to save a timestamp of the last time the conversation window was open.
I was wondering has anyone run into any similar problems, and if they have, how did they approach them.
Any help is appriciated...
Upvotes: 0
Views: 546
Reputation: 85
Found the solution. Use cookies to track the active conversation ID between page requests. Has added benefit of using timeout even if person logs out and then in again within a specified timeframe.
Thanks to cdslnte for triggering the thought...
Upvotes: 2