Skip to content

Commit babeaeb

Browse files
SignalR: Clarify groups (dotnet#32261)
* SignalR: Clarify groups * Removed h3 and fixed link. * Update groups.md Co-authored-by: Tom Dykstra <[email protected]> * Apply suggestions from code review --------- Co-authored-by: Tom Dykstra <[email protected]>
1 parent bc80718 commit babeaeb

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

aspnetcore/signalr/groups.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ description: Overview of ASP.NET Core SignalR User and Group management.
55
monikerRange: '>= aspnetcore-2.1'
66
ms.author: bradyg
77
ms.custom: mvc
8-
ms.date: 05/17/2020
8+
ms.date: 04/04/2024
99
uid: signalr/groups
1010
---
1111

1212
# Manage users and groups in SignalR
1313

1414
By [Brennan Conroy](https://github.com/BrennanConroy)
1515

16-
SignalR allows messages to be sent to all connections associated with a specific user, as well as to named groups of connections.
16+
SignalR allows messages to be sent to all connections associated with a specific user and to named groups of connections.
1717

1818
[View or download sample code](https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/signalr/groups/sample/) [(how to download)](xref:index#how-to-download-a-sample)
1919

@@ -32,13 +32,21 @@ Send a message to a specific user by passing the user identifier to the `User` f
3232

3333
## Groups in SignalR
3434

35-
A group is a collection of connections associated with a name. Messages can be sent to all connections in a group. Groups are the recommended way to send to a connection or multiple connections because the groups are managed by the application. A connection can be a member of multiple groups. Groups are ideal for something like a chat application, where each room can be represented as a group. Connections are added to or removed from groups via the `AddToGroupAsync` and `RemoveFromGroupAsync` methods.
35+
A group is a collection of connections associated with a name. Messages can be sent to all connections in a group. Groups are the recommended way to send to a connection or multiple connections because the groups are managed by the application. A connection can be a member of multiple groups. Groups are ideal for something like a chat application, where each room can be represented as a group.
36+
37+
### Add or remove connections from a group
38+
39+
Connections are added to or removed from groups via the `AddToGroupAsync` and `RemoveFromGroupAsync` methods:
3640

3741
[!code-csharp[Hub methods](groups/sample/Hubs/ChatHub.cs?range=15-27)]
3842

39-
Group membership isn't preserved when a connection reconnects. The connection needs to rejoin the group when it's re-established. It's not possible to count the members of a group, since this information is not available if the application is scaled to multiple servers.
43+
It's safe to add a user to a group multiple times, no exception is thrown in the case that the user already exists in the group.
44+
45+
Group membership isn't preserved when a connection reconnects. The connection needs to rejoin the group when it's re-established. It's not possible to count the members of a group, since this information isn't available if the application is scaled to multiple servers.
46+
47+
Groups are kept in memory, so they won't persist through a server restart. Consider the Azure SignalR service for scenarios requiring group membership to be persisted. For more information, see [Azure SignalR](/azure/azure-signalr/signalr-overview)
4048

41-
To protect access to resources while using groups, use [authentication and authorization](xref:signalr/authn-and-authz) functionality in ASP.NET Core. If a user is added to a group only when the credentials are valid for that group, messages sent to that group will only go to authorized users. However, groups are not a security feature. Authentication claims have features that groups do not, such as expiry and revocation. If a user's permission to access the group is revoked, the app must remove the user from the group explicitly.
49+
To protect access to resources while using groups, use [authentication and authorization](xref:signalr/authn-and-authz) functionality in ASP.NET Core. If a user is added to a group only when the credentials are valid for that group, messages sent to that group will only go to authorized users. However, groups are not a security feature. Authentication claims have features that groups don't, such as expiry and revocation. If a user's permission to access the group is revoked, the app must remove the user from the group explicitly.
4250

4351
> [!NOTE]
4452
> Group names are case-sensitive.

0 commit comments

Comments
 (0)