SignalR connectionId of a specific client

On my site users can follow each other and when this event happened I want to show the correct message for both users.

I found many solutions like this and this , but I cannot use it, maybe I need more details: -.

My site userId

has a PK in the DB and I store this in Session

and userId

other users embedded in html like this.

@foreeach(var item in Model)
{
     <div>@item.name</div>
     <button id="@item.userId">Follow</button> 
}

      

Startup.cs

    public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        var idProvider = new CustomUserIdProvider();

        GlobalHost.DependencyResolver.Register(typeof(IUserIdProvider), () => idProvider);          

        // Any connection or hub wire up and configuration should go here
        app.MapSignalR();
    }
}

      

myHub.cs

public class MyHub : Hub
{
     public void Send(string userId, string name, string message)
     {
          Clients.User(userId).broadcastMessage(name, "message 1");
          Clients.Caller.broadcastMessage(name, "message 2");

     }
}

      

Q myHub.cs

userId

is the userId

target user to follow? if so, how does SignalR diagnose the target user? I do not understand.

And in this solution that I was found there is a class CustomUserIdProvider

for find userId

, but I have the userId

target user in<button>

What's the solution for my problem?

+3


source to share





All Articles