Updating SignalR Application to 2.0

Introduction

As you know SignalR is a library that adds real-time web functionality to the development of ASP.NET applications and apart from that the current version of SignalR 2.0 offers a consistent development experience across server platforms using OWIN. This article describes the procedure to update SignalR applications to version 2.0.

In this article, I am using an existing web application developed in a MVC 5 project template that is a real time web app with SignalR as I defined in SignalR in MVC 5. We'll update it to SignalR version 2.0.

So, let's proceed with the following procedure.

Step 1: Open the Library Package Manager then select "Package Manager Console" and enter the following command:

Uninstall-Package Microsoft.AspNet.SignalR -RemoveDependencies

Uninstalling AspNet SignalR Dependency

Step 2: Enter the following command to update SignalR:

Install-Package Microsoft.AspNet.SignalR

Installing AspNet SignalR

Step 3: Open the Chat.cshtml page.

Solution Explorer of MVC App

Step 4: Update the Script reference with the following reference:

<script src="~/Scripts/jquery.signalR-2.0.1.js"></script>

Step 5: Open the Global.asax file and remove the MapHubs call method as shown below:

protected void Application_Start()

{

    //RouteTable.Routes.MapHubs();

    AreaRegistration.RegisterAllAreas();

    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

    RouteConfig.RegisterRoutes(RouteTable.Routes);

    BundleConfig.RegisterBundles(BundleTable.Bundles);

}

Step 6: Create an OWIN Startup class.

 OWIN Startup Class

Step 7: Open the OWIN Startup class and replace the code with the code below:

using Microsoft.Owin;

using Owin;

 

[assembly: OwinStartupAttribute(typeof(SignalRDemo.Startup))]

namespace SignalRDemo

{

    public partial class Startup

    {

        public void Configuration(IAppBuilder MyApp)

        {

            MyApp.MapSignalR();

        }

    }

}

 

The assembly attribute adds the class to OWIN's Startup class so that the Configuration() executes when OWIN starts up. This execute the MapSignalR() to create routes for all SignalR hubs in the application.

Step 7: Now, just build the solution and run the application. While on the browser chatting session copy the URL and paste it to another browser to continue the chat.

Summary

With this article you can update your application with SignalR version 2.0. You can enable it in your existing application or create your new application with this SignalR update. Thanks for reading.

Up Next
    Ebook Download
    View all
    Learn
    View all