csharp-signalr

Enforce SignalR Hub best practices for ASP.NET Core projects.

Updated Mar 1, 2026
One-click install
npx skills add https://github.com/CloudyWing/ai-dotfiles --skill csharp-signalr
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: csharp-signalr
Source: https://github.com/CloudyWing/ai-dotfiles/tree/main/skills/csharp-signalr
Command: npx skills add https://github.com/CloudyWing/ai-dotfiles --skill csharp-signalr

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Prevents common SignalR Hub implementation mistakes and ensures reliable, secure, and scalable real-time messaging by prescribing correct Hub lifetime, state management, authorization, error handling, and scale-out patterns.

Core Features & Use Cases

  • Hub lifetime & state guidance: Clarifies that Hub instances are transient and forbids storing per-connection state in instance fields, recommending external stores like Redis, databases, or IMemoryCache.
  • Connection, group, and messaging patterns: Explains OnConnected/OnDisconnected hooks, meaningful group naming, and sending messages from outside hubs via IHubContext.
  • Authentication, errors, and scale-out: Shows JWT-in-query handling for WebSockets, use of HubException for structured client errors, and options for scaling with Redis Backplane or Azure SignalR Service.
  • Use case: Apply these rules when building chat systems, live notifications, or collaborative features to avoid lost state, insecure tokens, and cross-instance message loss.

Quick Start

Ask the AI to review or generate SignalR Hub code following csharp-signalr rules ensuring transient Hubs, no instance fields, external state storage, correct group management, JWT query handling for WebSockets, HubException usage for structured errors, and Redis or Azure backplane configuration for scale-out.

Frequently Asked Questions about csharp-signalr

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I manage state in SignalR Hubs without losing data?

SignalR Hub instances are transient, so you cannot store per-connection state in instance fields. You must use external state stores like Redis, databases, or IMemoryCache to persist data across Hub method calls.

How do I authenticate WebSocket connections in SignalR?

To authenticate SignalR WebSocket connections, you must handle JWT tokens passed through the query string. This approach ensures secure real-time messaging when standard headers are not supported by the WebSocket protocol.

What is the best way to scale out SignalR across multiple instances?

The best way to scale out SignalR is to configure a Redis Backplane or use the Azure SignalR Service. These backplane strategies prevent cross-instance message loss and ensure reliable real-time messaging.

How do I send SignalR messages from outside a Hub?

To send SignalR messages from outside a Hub, you should inject and use IHubContext. This pattern allows external services or controllers to push real-time updates to connected clients and manage group memberships.

How do I handle errors in SignalR Hubs for client-side processing?

To handle errors in SignalR Hubs, throw a HubException to return structured error details to the client. This prevents exposing sensitive server stack traces while allowing the client to process real-time messaging failures safely.

When do I need to use SignalR OnConnected and OnDisconnected hooks?

You use the SignalR OnConnected and OnDisconnected hooks to manage the connection lifecycle. These hooks are essential for tracking user presence, registering meaningful group names, and cleaning up resources when connections drop.