Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
Ravi Vishwakarma
22-May-2025In SignalR, you can handle user connection and disconnection events by overriding the virtual methods
OnConnectedAsync
andOnDisconnectedAsync
in yourHub
class.Basic Implementation
Notes
1. User Identification
Context.ConnectionId
: Unique for each connection.Context.UserIdentifier
: Set automatically if authentication is configured.Context.User
: FullClaimsPrincipal
for the user.To customize
UserIdentifier
, use a customIUserIdProvider
:Register it:
2. Common Use Cases
Example: Notifying Others