signalr-hub

How to read headers data in hub SignalR ASP.NET Core 2.1

天涯浪子 提交于 2021-02-20 09:47:26
问题 I'm trying to pass userId to hub on connection to signalR. This is how client sets up the connection: connection = new HubConnectionBuilder() .WithUrl("http://localhost:56587/hub", options => { options.Headers["UserId"] = loginTextBox.Text; }) .AddMessagePackProtocol() .Build(); How can I read this header in OnConnectedAsync() method in my hub? 回答1: To get Header Value as string: public override async Task OnConnectedAsync() { var httpCtx = Context.GetHttpContext(); var someHeaderValue =

How to read headers data in hub SignalR ASP.NET Core 2.1

折月煮酒 提交于 2021-02-20 09:47:00
问题 I'm trying to pass userId to hub on connection to signalR. This is how client sets up the connection: connection = new HubConnectionBuilder() .WithUrl("http://localhost:56587/hub", options => { options.Headers["UserId"] = loginTextBox.Text; }) .AddMessagePackProtocol() .Build(); How can I read this header in OnConnectedAsync() method in my hub? 回答1: To get Header Value as string: public override async Task OnConnectedAsync() { var httpCtx = Context.GetHttpContext(); var someHeaderValue =

Access SignalR from domain services and application layer

。_饼干妹妹 提交于 2021-02-11 13:32:53
问题 This is directly related to calling a SignalR Hub from the Application Service Layer in ASP.NET Boilerplate .NET Core version. As per the solution, SignalR hub implementation should be done in Web layer. But the dependency structure of the projects are like: App depends on Domain.Core Web.Core depends on App Web.Host depends on Web.Core Two questions: To be able to use the Hub in both Domain.Core and App projects, how should I wire it all up? If I define the interface in App layer with a null

SignalR 2, Autofac, OWIN WebAPI will not pass message from server to hub

天大地大妈咪最大 提交于 2021-02-11 13:10:12
问题 I have tried several variations over the past several weeks and so far all I can do is pass a message from the UI to the server and back. I am unable to pass a message from my controller or other method outside the hub to the UI. It seems like I am not getting an instance of the HubContext. I've created a basic demo app from scratch and uploaded here: https://github.com/cdecinkoKnight/SignalRDemo-help I have a basic hub (MessageHub): [HubName("messages")] public class MessageHub : Hub,

SignalR 2, Autofac, OWIN WebAPI will not pass message from server to hub

牧云@^-^@ 提交于 2021-02-11 13:10:05
问题 I have tried several variations over the past several weeks and so far all I can do is pass a message from the UI to the server and back. I am unable to pass a message from my controller or other method outside the hub to the UI. It seems like I am not getting an instance of the HubContext. I've created a basic demo app from scratch and uploaded here: https://github.com/cdecinkoKnight/SignalRDemo-help I have a basic hub (MessageHub): [HubName("messages")] public class MessageHub : Hub,

How to send Parameter/Query in HubConnection SignalR Core 2.1

为君一笑 提交于 2021-02-10 14:50:32
问题 I'm trying to send parameters into connection to signalr Connection = new HubConnectionBuilder() .WithUrl("https://familyapp.azurewebsites.net/StoreHub?token=123") .Build(); await Connection.StartAsync(); In my server side i take this parameter from HttpContext: public override async Task OnConnectedAsync() { var group = Context.GetHttpContext().Request.Query["token"]; string value = !string.IsNullOrEmpty(group.ToString()) ? group.ToString() : "default"; await Groups.AddToGroupAsync(Context

How to pass a parameter to hub in SignalR?

☆樱花仙子☆ 提交于 2021-02-09 08:27:34
问题 My code in SignalR hub: public class AlertHub : Hub { public static readonly System.Timers.Timer _Timer = new System.Timers.Timer(); static AlertHub() { _Timer.Interval = 60000; _Timer.Elapsed += TimerElapsed; _Timer.Start(); } static void TimerElapsed(object sender, System.Timers.ElapsedEventArgs e) { //Random rnd = new Random(); //int i = rnd.Next(0,2); Alert alert = new Alert(); i = alert.CheckForNewAlerts(EmpId); var hub = GlobalHost.ConnectionManager.GetHubContext("AlertHub"); hub

SignalR - how to disable WebSockets (but keep other transports active)?

℡╲_俬逩灬. 提交于 2021-02-08 09:05:53
问题 In both a C# client and Web Client - how do I tell signalR - "Try everything but websockets"? I have the following in my web code: window.hubReady = $.connection.hub.start({ transport: 'longPolling' }); But this is just javascript and longpolling; I'm looking for the configuration for both JS and C# clients to only remove websockets as a transport. How can this be done? 回答1: On the server: public class Startup { public void Configuration(IAppBuilder app) { DisableWebSockets(GlobalHost

SignalR - how to disable WebSockets (but keep other transports active)?

夙愿已清 提交于 2021-02-08 09:03:44
问题 In both a C# client and Web Client - how do I tell signalR - "Try everything but websockets"? I have the following in my web code: window.hubReady = $.connection.hub.start({ transport: 'longPolling' }); But this is just javascript and longpolling; I'm looking for the configuration for both JS and C# clients to only remove websockets as a transport. How can this be done? 回答1: On the server: public class Startup { public void Configuration(IAppBuilder app) { DisableWebSockets(GlobalHost

SignalR connection handling on app pool recycle

Deadly 提交于 2021-02-07 11:57:14
问题 I'm using SignalR (0.5.3) Hubs for a chat app where each keystroke is sent to the server (saved in the DB), relayed to all clients and a return value (a string token of sorts) is sent back from the server. It works fine, until the app pool recycles, then it stops relaying the keystrokes to all the clients (because the in-memory server state is lost I suppose) and the server doesn't return back any values as well. At this point, I suppose all requests via SignalR are queued by IIS and then