Search code examples
clientsignalrasp.net-mvc-5userid

How do I provide a SignalR connection for a user in the database?


I do not use Asp.NET Membership. Instead, I have my own membership system. I keep my own user information in the database.

For example,

James Bond, UserID {AF433-DA322 ......-.........} Uniqueidentifier

I am creating a connectionID for SignalR or I want to define a member. How do I relate to user information in my own database?

The purpose is to send a message to the member in the database.

For example;

GUID userID = {AF433-DA322 .......-..........} [James Bond :)]

Clients.User(userID).send(message);

Anyhow, how do you establish a relationship between the user and the database? How can I promote it?


Solution

  • This can be achieved using a SignalR mapping table. This mapping table contains GUID userID and SignalR connection id at the moment. Triggering an update or insert for above table (SignalR mapping table) should be followed by connection state changes in Client and server side. Example .

    Connected: Implement RegisterUser method in server side and call it from Client side followed by SinglaR connected event.

    Disconnected: Subscribe to the disconnected method in server-side and do database table update according to your logic.

    Now you can use above database table whenever you want to send a message to a user.