signalr-hub

Context.User.Identity.Name is null with SignalR 2.X.X. How to fix it?

醉酒当歌 提交于 2019-11-26 10:57:31
问题 This is driving me insane. I\'m using latest signalR release (2.0.2). This is my hub code (OnConnected) public override Task OnConnected() { //User is null then Identity and Name too. Connections.Add(Context.User.Identity.Name, Context.ConnectionId); return base.OnConnected(); } And this is my Controller\'s login method: [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid) { var user =

Get number of listeners, clients connected to SignalR hub

僤鯓⒐⒋嵵緔 提交于 2019-11-26 09:28:16
问题 Is there a way to find out the number of listeners (clients connected to a hub?) I\'m trying to run/start a task if at least one client is connected, otherwise do not start it: [HubName(\"taskActionStatus\")] public class TaskActionStatus : Hub, IDisconnect { static CancellationTokenSource tokenSource; public void GetTasksStatus(int? siteId) { tokenSource = new CancellationTokenSource(); CancellationToken ct = tokenSource.Token; ITaskRepository taskRepository = UnityContainerSetup.Container

SignalR + posting a message to a Hub via an action method

情到浓时终转凉″ 提交于 2019-11-26 05:16:52
问题 I am using the hub- feature of SignalR (https://github.com/SignalR/SignalR) to publish messages to all subscribed clients: public class NewsFeedHub : Hub public void Send(string channel, string content) { Clients[channel].addMessage(content); } This works fine when calling \"Send\" via Javascript, but I would also like the web application to publish messages (from within an ASP.NET MVC action method). I already tried instantiating a new object ob NewsFeedHub and calling the Send method, but