2
votes

In the SignalR (server) hub I want do a license check. If the check negativ then I want in the OnConnected of the Hub block the connection. The client should get in the Hub start the Task as canceled with a message (no valid licence).

When I return a Task with a Aggregate Exception in the OnConnected of the SignalR Hub then the client gets a fault state, with a timeout exception.

How can I block the connection to the SignalR hub and give the client a message why I have block the connection?

2

2 Answers

1
votes

As far as I know you can't just start or stop connections already on the server. The client has to disconnect itself. If you want to use the hub for licence check you need to have the client connect - send licence info - server checks and if it is invalid call $client.disconnect on the client.

The other option like blorkfish mentions is to allow them to connect, add them to a list and check this when they call methods on the server.

0
votes

I don't think that you should block the connection with an Exception. Your client would then not be able to tell if there was a genuine error in the SignalR connection.

Rather send a specific SignalR message back that there is no license - and then manage the connection object on the server side.
Keep a list of licensed connections, and a list of unlicensed connections.
So instead of using Clients.All to broadcast, use Clients.Client("< client_connection_id >") to broadcast.
Hope this helps.