Как получить идентификатор соединения от концентратора к серверному контроллеру в ядре .net?C#

Место общения программистов C#
Anonymous
Как получить идентификатор соединения от концентратора к серверному контроллеру в ядре .net?

Сообщение Anonymous »

У меня есть этот хаб в signalr:

Код: Выделить всё

    using Microsoft.AspNetCore.SignalR;
using System.Collections;
using System.Diagnostics;

namespace BulletControls.Hub
{
public class ForumHub : Hub
{
public static Dictionary hubConnections = new Dictionary();

public override async Task OnConnectedAsync()
{
hubConnections.Add(Context.ConnectionId, "");
await Clients.Client(Context.ConnectionId).SendClientConnect(Context.ConnectionId);
}
public override async Task OnDisconnectedAsync(Exception? exception)
{
hubConnections.Remove(Context.ConnectionId);
await base.OnDisconnectedAsync(exception);
}
public async Task RecieveClientSessionGuid(string guid, string connectionId)
{
hubConnections[connectionId] = guid;
}
public async Task SendForumNotificationUpdateToClient(string guid, int commentId)
{
string connectionId = hubConnections.FirstOrDefault(x => x.Value == guid).Key;
await Clients.Client(connectionId).SendForumNotificationUpdateToClient($"{commentId}");
}

public string GetConnectionId(string guid)
{
string connectionId = hubConnections.FirstOrDefault(x => x.Value == guid).Key;
return connectionId;
}
}

public interface IComHub
{
Task SendClientConnect(string message);
Task SendForumNotificationUpdateToClient(string message);
}
}
И у меня есть эта конечная точка в моем контроллере:

Код: Выделить всё

    [Route("/Forum/Threads/StoreThreadComment")]
public async Task StoreThreadComment(ThreadCommentInput threadComment)
{
forumHub.Clients.Client(??).SendForumNotificationUpdateToClient("");
}
Как получить идентификатор соединения из концентратора и получить доступ к идентификатору соединения внутри конечной точки контроллера?

Подробнее здесь: https://stackoverflow.com/questions/795 ... oller-in-n

Вернуться в «C#»