Место общения программистов C#
Anonymous
Как получить идентификатор соединения от концентратора к серверному контроллеру в ядре .net?
Сообщение
Anonymous » 04 дек 2025, 17:38
У меня есть этот хаб в 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
1764859107
Anonymous
У меня есть этот хаб в signalr: [code] 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); } } [/code] И у меня есть эта конечная точка в моем контроллере: [code] [Route("/Forum/Threads/StoreThreadComment")] public async Task StoreThreadComment(ThreadCommentInput threadComment) { forumHub.Clients.Client(??).SendForumNotificationUpdateToClient(""); } [/code] Как получить идентификатор соединения из концентратора и получить доступ к идентификатору соединения внутри конечной точки контроллера? Подробнее здесь: [url]https://stackoverflow.com/questions/79567743/how-do-you-get-the-connection-id-from-the-hub-to-the-serverside-controller-in-n[/url]