Using SignalR in ASP.NET 5

Posted by Anuraj on Thursday, January 29, 2015

.Net ASP.Net ASP.Net MVC Visual Studio

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 :)


Similar Posts


Did you like this article? Share it with your friends

Facebook Twitter Google+ LinkedIn Reddit StumbleUpon



MVP
Subscribe
Archives


Copyright © 2017 - Anuraj P. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Hosted with ❤ by GitHub