SignalR doesn’t use Session on server

SignalR connections (including the connection underlying all Hub operations for a client) do not support Session state. You could enable it if you wanted to but we’d strongly recommend against it as session state access serializes requests for a given client, meaning you won’t really get the benefit from SignalR duplex messaging anymore, as one … Read more

SignalR calling client method from outside hub using GlobalHost.ConnectionManager.GetHubContext doesn’t work. But calling from within the hub does

I came across with same issue couple days ago. That took my 2 days to find solution and resolve it. After some serious investigate the problems root cause was the signalr dependency resolver that I set customly. At the end I found this link and that was saying this: Replacing the DependencyResolver You can change … Read more

signalR – getting username

When using SignalR hubs you can use the HubCallerContext.User property to: Gets the user that was part of the initial http request. So try it with: public Task Join() { string username = Context.User.Identity.Name; //find group based on username string group = getGroup(username) return Groups.Add(Context.ConnectionId, group); }

Proper Hub dependency lifetime management for SignalR and Castle Windsor

I’ve had a bit similar problem but with Unity instead of Castle Windsor. My requirements: I wanted to avoid singleton registrations on the container. All objects are resolved in Hub and should be disposed on Hub destruction. Registrations reused across Web Api and SignalR. Object lifetime is managed by HierarchicalLifetimeManager – child containers resolve and … Read more

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

I found the final solution, this is the code of my OWIN startup class: public void Configuration(IAppBuilder app) { app.MapSignalR(); // Enable the application to use a cookie to store information for the signed i user app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString(“/Home/Index”) }); // Use a cookie to temporarily store information … Read more

Call a hub method from a controller’s action

The correct way is to actually create the hub context. How and where you do that is up to you, here are two approachs: Create a static method in your hub (doesn’t have to be in your hub, could actually be anywhere) and then you can just call it via AdminHub.SendMessage(“wooo”) public static void SendMessage(string … Read more

How to get SignalR Hub Context in a ASP.NET Core?

IConnectionManager does not exist any more in SignalR for ASP.Net Core. I’ve been using HubContext for getting access to a hub. public class HomeController : Controller { private readonly IHubContext<LiveHub> _hubContext; public HomeController(IHubContext<LiveHub> hubContext) { _hubContext = hubContext; } public void SendToAll(string message) { _hubContext.Clients.All.InvokeAsync(“Send”, message); } } I’m using .net core 2.0.0 and SignalR … Read more

tech