1

I need to track to which group specific connection belongs. I use Redis backplane and I have read the RedisHubLifetimeManager code. I see that they use IRedisFeature to store groups to which specific connection belongs.

I don't want to store the same information twice. But there is no any documentation how the Features collection works. Where the data is stored? Can I be sure that this data is not modified by e.g. user?

I want to use it as below:

public class MessagingHub : Hub
{
    private const string RECEIVE_MESSAGE_METHOD = "ReceiveMessage";

    public async Task SendMessageAsync(SendMessageDto sendMessageDto)
    {
        var feature = Context.Features.SingleOrDefault(p => p.Key.Name == "IRedisFeature").Value;
        var groups = feature.GetType().GetProperty("Groups")?.GetValue(feature) as HashSet<string>;
        if (groups is null || !groups.Contains(sendMessageDto.ConversationId))
            return;

        await Clients.Group(sendMessageDto.ConversationId).SendAsync(RECEIVE_MESSAGE_METHOD);// rest omitted
    }
}

But I'm not sure if I can rely on HubCallerContext.Features collection and on IRedisFeature. Can I? Is that secure (nobody can modify it, except SignalR hub)? How the HubCallerContext.Features works?

Szyszka947
  • 473
  • 2
  • 5
  • 21
  • If you need to use reflection to get the property, then you can't rely on the feature. SignalR can change how it works at any time. Generally if you need user/group info you need to manage it yourself because SignalR does not provide a mechanism that lists all connections in a user/group, especially when using multiple servers. – Brennan Jul 30 '23 at 00:33
  • If the backplane library has this information why they don't allow to use it (they maked it internal)? Strange for me. At least, how the `HubCallerContext.Features` works? I cant find appropriate documentation. – Szyszka947 Jul 30 '23 at 10:57

0 Answers0