signalr-hub

OnConnected method not called SignalR when I use shared connection in multiple hubs

我是研究僧i 提交于 2019-12-10 15:26:54
问题 We can create multiple hubs for different things, and to connect to each hub we can create multiple client side hubs with sharing connection so that, one connection being made to all hubs. Now, the problem arises that the hub onconnected method is not raising on each hub server side code. public class Hub1 : Hub { public override Task OnConnected() { return base.OnConnected(); } } public class Hub2 : Hub { public override Task OnConnected() { return base.OnConnected(); } } let say, on the

SignalR - HubContext and Hub.Context

╄→гoц情女王★ 提交于 2019-12-10 15:11:26
问题 I am new to signalR and reading the API and playing around with it. a bit confused about the Hub and its Context. That is, Hub.Context is not HubContext . HubContext I can get from GlobalHost.ConnectionManager.GetHubContext<THub>() and Hub.Context gives me a HubCallerContext which I am not sure how to use. What are their relationship? How can I get HubContext from Hub or Hub from HubContext ? 回答1: A result of poor naming. Hub.Context is the HTTP context from the caller (more like a request

Why is HTTPContext.Current.Session null using SignalR 2.x libraries in a ASP .Net MVC application?

爱⌒轻易说出口 提交于 2019-12-10 14:55:28
问题 I'm attempting to migrate our ASP.Net MVC application from using Signal R1.x tgo SignalR 2.x. I just found issue which will certainly cause us problems in our quest to move forward. Our web application is MVC based and makes heavy use of the HttpContext.Current.Session variable. When running with SignalR 1.x, everything is fine and dandy with Session. When we upgraded to SignalR 2.x, Session was suddenly null. I did a little googling and found the following links regarding the issue:

Detect SignalR Hub Client Disconnect instantly

两盒软妹~` 提交于 2019-12-10 14:42:58
问题 When is the SignalR Hub OnDisconnected raised on server side, for the the .net client that crash or close without calling the Stop method? I am testing with the SignalR .NET client, not the javascript client. If I call the Stop method on the client, the Hub will raise OnDisconnected method immediately. But if I close the client or kill the process, the Hub will raise OnDisconnected method only after about 10 seconds. How can I detect instantly that the client is disconnected? 回答1: Having read

Implementing Authorization in a Self Hosted SignalR Server accessed from Web

女生的网名这么多〃 提交于 2019-12-10 13:58:57
问题 I'm looking for some guidance on how to implement authorization security for SignalR on a back end service running in a self-hosted (non-IIS) environment, that is called from a Web application. The backend app is basically a monitor that fires SignalR events back to the HTML based client. This all works fine (amazingly well actually). However, we need to restrict access to the server for authenticated users from the Web site. So basically if a user is authenticated on the Web site, we need to

How use UrlHelper in signalR HubClass

眉间皱痕 提交于 2019-12-10 13:58:20
问题 I have a Chat class drived from Hub. I want to know if thers a way to built URL by URLHelper like : Url.Action("action","Controller"). as i can derived the class from 2 abstract classes (Hub, Controller) i dont know if thers other way to build complete URls and not Hard code. 回答1: I use this code in my Hub currently, I'm sure there is a better way to do this, but this works. Note: If you want a a fully qualified url, make sure you set the domain correctly (example.com). protected virtual

SignalR 2.0 in VS2012 registration and Dependency Injection

南楼画角 提交于 2019-12-10 11:46:19
问题 I was able to work with SignalR 1.13 with my own DI like this: //Funq container GlobalHost.DependencyResolver = new FunqDependencyResolver(container); RouteTable.Routes.MapHubs(); Now with the new version 2.0 I am stuck. using Microsoft.Owin; using Owin; //SignalR 2.0 no longer uses RouteTable.Routes.MapHubs(); [assembly: OwinStartup(typeof(SignalRChat.Startup))] namespace SignalRChat { public class Startup { public void Configuration(IAppBuilder app) { app.MapSignalR(); } } } (New SignalR 2

SignalR Hub Overloads

若如初见. 提交于 2019-12-09 17:19:11
问题 I tried creating a basic hub with two Receive methods, one accepts a string and the other an int. This causes an error stating that the method cannot be resolved. Commenting out one of the methods gets rid of the error and everything works. Is it possible to have overloads of a method in my hub? Could something like overloads be done? 回答1: SignalR does support overloading server-side Hub methods, but the overloads must have a different arity, i.e. take a different number of arguments. If the

Passing strongly typed Hubs in SignalR

99封情书 提交于 2019-12-09 08:40:44
问题 I've just updated some SignalR references and things have changed somewhat in order to allow for generically typed Hubs Hub<T> . In the existing examples and documentation such as at: Server-Broadcast-with-Signalr we have a static class holding references to clients via the following mechanisms: public class StockTicker() { private readonly static Lazy<StockTicker> _instance = new Lazy<StockTicker>( () => new StockTicker(GlobalHost.ConnectionManager.GetHubContext<StockTickerHub>().Clients));

SignalR and HttpContext/Session

只谈情不闲聊 提交于 2019-12-09 08:20:40
问题 I understand why SignalR doesn't give you access to the HttpContext. However, this is quite problematic for us. Let me explain: Our application is a Multi-Tenant application where the user chooses the environment while logging in. This basically registers the ConnectionStringName in the HttpSession. In our SignalR Hub, we need to access the database on Disconnect . But this is not possible because we have no HttpContext at this point and cannot determine the environment to write to. Can