Logo

dev-resources.site

for different kinds of informations.

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

Published at
8/6/2024
Categories
csharp
dotnet
dotnetcore
aspdotnet
Author
matinabaszada
Author
13 person written this
matinabaszada
open
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!

aspdotnet Article's
30 articles in total
Favicon
Uploading Files to Amazon S3 in ASP.NET Core with Razor Pages
Favicon
Managing Relationships, Migrations, and Performance Optimization in ASP.NET Core MVC
Favicon
DevExpress - Enhancing ASP.NET Web Forms with the ASPxGridView Control
Favicon
DevExpress - Simplifying Server-to-Client Data Transfer with ASPxCallback JSProperties
Favicon
šŸš€ [ASP.NET] How to design API allowed client specific fields?
Favicon
Web application translation in two ways.
Favicon
[Boost]
Favicon
[Boost]
Favicon
Command Pattern with Undo and Redo in C#.NET
Favicon
Server Sent Events in ASP.NET Core
Favicon
Everything New in .NET 9: The Ultimate Developer's Guide
Favicon
Is .NET 9 beneficial for Blazor?
Favicon
The Guardian Middleware: Handling Errors Globally in ASP.NET
Favicon
.NET Aspire: A Game-Changer for Cloud-Native Development Services
Favicon
Top 20+ Full-stack Projects For Beginners in C#, ASP.NET , .NET CORE
Favicon
šŸ” How to Implement OAuth 2.0 Authentication in ASP.NET Core with External APIs
Favicon
Performance Optimization Techniques for ASP.NET Core Applications
Favicon
Patterns for Routing in ASP.NET Core minimal APIs
Favicon
How to prevent XSS Attacks in ASP.NET Core Web API
Favicon
MyHotixRestaurant
Favicon
Microservices using ASP.NET Core, Ocelot, MongoDB and JWT
Favicon
suggest design warehouse management
Favicon
Maximizing ASP.NET Potential through Azure Development Services
Favicon
10 Lessons I Learned from Using Aspire in Production
Favicon
Logging in ASP.NET Core
Favicon
What is ASP.NET used for in software development?
Favicon
Concepts of a Ticket in ASP.NET Identity
Favicon
Building a Scalable Multi-Tenant Community Management System with ASP.NET and Angular
Favicon
How to Manage Persistent Connections in a WhatsApp-like Chat Application Using ASP.NET SignalR and EF Core?
Favicon
Deep Dive ASP.NET Core Middleware : Part 1

Featured ones: