Using SignalR in ASP.NET 5

Long back I did some post on SignalR, A collaboration White Board using HTML 5 and SignalR. In this post I am converting that solution to work with ASP.NET 5.

To use SignalR, you need to add “Microsoft.AspNet.SignalR.Server” reference in the project.json file.

{
    "dependencies": {
        "Microsoft.AspNet.Diagnostics": "1.0.0-beta1",
        "Microsoft.AspNet.Hosting": "1.0.0-beta1",
        "Microsoft.AspNet.Server.WebListener": "1.0.0-beta1",
        "Microsoft.AspNet.StaticFiles": "1.0.0-beta1",
		"Microsoft.AspNet.SignalR.Server": "3.0.0-beta1"
    },
    "commands": {
        "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5010"
    },
    "frameworks": {
		"aspnet50": {},
        "aspnetcore50": {}
	}
}

Also you need Microsoft.AspNet.StaticFiles reference, as you need to serve Javascript and HTML files.

Now you need to modify the startup.cs file to use SignalR, similar to MVC, Microsoft introduced some extenstion methods to enable support for SignalR.

public class Startup
{
	public void Configure(IApplicationBuilder app)
	{
		app.UseServices(services =>
		{
			services.AddSignalR();
		});
		app.UseFileServer();
		app.UseSignalR();
	}
}

And you are ready to run the SignalR services. I have modified the script file to support SignalR client side changes. You can find the source code on github.

Happy Programming :)