DEV Community

Cosmin Irimescu
Cosmin Irimescu

Posted on

Real-Time Cross-Tab Notifications with SignalR in ASP.NET Core

Hey dev community! πŸ‘‹

I've just published a sample repository demonstrating how to implement real-time notifications with SignalR in ASP.NET Core. I built this while exploring cross-tab communication possibilities, and I thought it might be useful for others too.

What's Inside?

The repository contains a clean implementation showing how to:

  • Set up SignalR in ASP.NET Core
  • Handle real-time notifications across multiple browser tabs
  • Manage automatic reconnection
  • Implement animated notifications

Key Features

public class NotificationHub : Hub
{
    public override async Task OnConnectedAsync()
    {
        string userId = Context.User.FindFirst("uid").Value;
        await Groups.AddToGroup(Context.ConnectionId, userId);
        await base.OnConnectedAsync();
    }

    public async Task SendNotification(string message)
    {
        await Clients.All.SendAsync("ReceiveNotification", message);
    }
}
Enter fullscreen mode Exit fullscreen mode

The implementation is straightforward yet powerful. It handles multiple tabs seamlessly, making it perfect for modern web applications.

Where to Find It?

While the tutorial is in Italian, the code and commit messages are in English. If you're interested in the implementation details, I've written a comprehensive guide on my blog.

Tech Stack

  • ASP.NET Core 8.0
  • SignalR
  • JavaScript
  • CSS3 for animations

Feel free to star the repo if you find it useful or raise issues if you have suggestions for improvements!

dotnet #signalr #aspnetcore #webdev #github #opensource

Top comments (0)