Summary of SignalR Connections and Contexts
In SignalR, a connection (or context) represents an individual connection to the server. Each connection has its own context with several important properties:
- ConnectionId
- A unique identifier for each connection.
- It is a GUID by default but can be overridden (not recommended).
- Refreshing the page generates a new ConnectionId.
- UserIdentifier
- Used when integrating with ASP.NET Identity.
- Represents the username or unique identifier of the authenticated user.
- Only available if the user is authenticated.
- User
- The entire principal object from ASP.NET Identity.
- Provides more detailed information about the authenticated user.
- Only available if the user is authenticated.
- Items
- A dictionary for storing metadata related to the connection.
- Useful for persisting data across multiple hub calls.
- ConnectionAborted
- A cancellation token that indicates if the connection has been aborted.
- Useful for handling long-running asynchronous tasks.
Understanding these properties helps in managing and utilizing SignalR connections effectively.