Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR - OnConnect() authorization - how to disconnect unauthorized user?

Tags:

signalr

In my hub, I have something like this (pseudocode):

public override Task OnConnected()
{
    var isLegal = Authorize();
    if (!isLegal) //not authorized
    {
        //how do I deny him this connection?
    }
    return base.OnConnected();
}

How to disconnect/deny connection to a user?

like image 989
ojek Avatar asked Sep 24 '13 15:09

ojek


People also ask

How do I disconnect SignalR client?

SignalR version 2 does not have a built-in server API for disconnecting clients. There are plans for adding this functionality in the future. In the current SignalR release, the simplest way to disconnect a client from the server is to implement a disconnect method on the client and call that method from the server.

How do you authenticate a SignalR hub?

In a browser-based app, cookie authentication allows your existing user credentials to automatically flow to SignalR connections. When using the browser client, no additional configuration is needed. If the user is logged in to your app, the SignalR connection automatically inherits this authentication.

How many connections can SignalR handle?

In the default mode, the app server creates five server connections with Azure SignalR Service. The app server uses the Azure SignalR Service SDK by default. In the following performance test results, server connections are increased to 15 (or more for broadcasting and sending a message to a big group).

How do I set SignalR connection timeout?

Configuration. ConnectionTimeout = TimeSpan. FromSeconds(40); // Wait a maximum of 30 seconds after a transport connection is lost // before raising the Disconnected event to terminate the SignalR connection.


1 Answers

Add authorize attribute over the class,the user will be denied, if not authenticated.

like image 123
Ujjwal Kumar Gupta Avatar answered Sep 22 '22 02:09

Ujjwal Kumar Gupta