Getting started with SignalR using ASP.NET Framework

SignalR is way to have bi-directional/live communication between client and server.

Install NuGet package: Microsoft ASP.NET SignalR.
It will add SignalR JavaScript

Now lets add Startup class in root directory, if not available in the project

using Microsoft.Owin;
using Owin;

[assembly: OwingStartup(typeof(SignalRDemo.Startup))]
namespace SignalRDemo
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.MapSignalR();
        }
    }
}

Now add SignalR Hub to serve the client.

namespace SignalRDemo
{
    public class SignalRHub : Hub
    {
        public static void SendNotifications()
        {
            // todo: after hub started by client
        }
    }
}

Now add SignalR script on client page where we want live interaction.

<script src="/Scripts/jquery.signalR-2.0.2.js"></script>
    <script src="~/signalr/hubs"></script>

    <script type="text/javascript">

        $(function () {       
            var hub = $.connection.signalRHub;
            hub.client.sendNotifications = function (message) {
                // todo: client
            };

            $.connection.hub.start({ transport: 'auto' }, function () {
            });
        });
    </script>

6 thoughts on “Getting started with SignalR using ASP.NET Framework”

  1. please mention use and benefits of signal R so that we can understand when we will used or which scenarios we should used signal R.

  2. Have you ever thought about including a little
    bit more than just your articles? I mean, what you say is important and all.
    Nevertheless think of if you added some great graphics or videos
    to give your posts more, “pop”! Your content is excellent but with images
    and clips, this website could undeniably be one of the greatest in its niche.
    Great blog!

Leave a Reply to Aditi Cancel reply

Your email address will not be published. Required fields are marked *