SignalR Typenamehandling

This can be done by taking advantage of the fact that your types and the SignalR types are in different assemblies. The idea is to create a JsonConverter that applies to all types from your assemblies. When a type from one of your assemblies is first encountered in the object graph (possibly as the root … Read more

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

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

No access to the Session information through SignalR Hub. Is my design is wrong?

You shouldn’t use Session with SignalR (see SignalR doesn’t use Session on server). You identify logical connections by their connection id which you can map to user names. The underlying problem is that access to SessionState is serialized in ASP.NET to ensure state consistency, so each request to the hub would block other requests. In … Read more

Can I incorporate both SignalR and a RESTful API?

Take a look at the video from this blog post. It explains exactly how you can use WebAPI with SignalR. Essentially, Web API + SignalR integration consists in this class: public abstract class ApiControllerWithHub<THub> : ApiController where THub : IHub { Lazy<IHubContext> hub = new Lazy<IHubContext>( () => GlobalHost.ConnectionManager.GetHubContext<THub>() ); protected IHubContext Hub { get … Read more

How SignalR works internally?

No, SignalR is an abstraction over a connection. It gives you two programming models over that connection (hubs and persistent connections). SignalR has a concept of transports, each transport decides how data is sent/received and how it connects and disconnects. SignalR has a few built in transports: WebSockets Server Sent Events Forever Frame Long polling … Read more

Self hosted OWIN and urlacl

so it turns out you need to pass in a url into StartOptions in the same format as the urlacl. Changing the start options to the code below fixed the problem. now the app is accessible across the network. var options = new StartOptions(“http://*:8989”) { ServerFactory = “Microsoft.Owin.Host.HttpListener” };

Get number of listeners, clients connected to SignalR hub

There is no way to get this count from SignalR as such. You have to use the OnConnect() and OnDisconnect() methods on the Hub to keep the count yourself. Simple example with a static class to hold the count: public static class UserHandler { public static HashSet<string> ConnectedIds = new HashSet<string>(); } public class MyHub … Read more

How to implement real time data for a web page

SignalR This is the answer I’m most excited to share, because it represents a much cleaner implementation that is lightweight and works well in today’s mobile (data constricted) environment. There have been several methods over the years to provide “realtime” pushing of data from the server to the client (or the appearance of pushing data). … Read more

tech