DEV Community

MetinAbaszade
MetinAbaszade

Posted on

How to Manage Persistent Connections in a WhatsApp-like Chat Application Using ASP.NET SignalR and EF Core?

I'm currently developing a chat application similar to WhatsApp using C#, ASP.NET SignalR, and EF Core. My goal is to implement both group chats and one-to-one chats and store them in a database for persistence. However, I'm encountering an issue with managing user connections.

Each time a user connects to the SignalR hub, a new ConnectionId is generated. This requires me to re-add the user to their respective groups and one-to-one chats with each refresh. Essentially, every time the user refreshes the page, they leave and then rejoin all their chats.

Although I can store the ConnectionId in cache or in the database, it becomes useless because SignalR will always generate a new ConnectionId upon reconnection. I doubt that real-world applications handle connections this way, so I’m looking for guidance on how to manage this situation effectively.

Here are my specific questions:

How can I persist user connections across page refreshes and disconnections?
Is this issue specific to web applications, or does it also occur in mobile and desktop applications?
What are the best practices for handling user reconnections in SignalR?
Can you recommend any resources or documentation that provide in-depth explanations and solutions for this issue?
I've searched online but found limited information on this topic. Any detailed explanations or pointers to comprehensive resources would be greatly appreciated.

You Can see my db structure below:
Image description

Thank you!

Top comments (0)