How I have used Sitecore SignalR

On a existing Sitecore project I had to use SignalR for a page to facilitate real-time update of the information for all the visitors/users that were interacting with that page.

Indeed I turned to Sitecore SignalR module and used as resources other blogs/websites that wrote about the subject:

Everything looked great, I’ve build my page with my entire functionality, getting to the point where I needed the username of the visitor of my page/site. Since my website is protected with ADFS Authentication, I had to protect the SignalR hub and to pass authentication information to clients. Then I’ve used this, from the official documentation, and I’ve changed the code from InitializeSignalR.cs where before the line

args.App.MapSignalR(Settings.SignalR.Path, new HubConfiguration());

I’ve added


And as for the username, I’ve save it into a cookie on the page load of the component that has the SignalR functionality, and then I’m using it into the JS functionality of my SignalR functionality.

Then, since our implementation will be residing on couple of servers that were behind a LoadBalancer, and it was needed that the messages distributed by SignalR to get to all clients so SignalR Scaleout with SQL Server was needed. I’ve used the documentation from here, as follows:

  1. Created a new empty database. The backplane will create the necessary tables in this database.
  2. Added an extra NuGet package to your application:
  3. Added the following code to InitializeSignalR.cs to configure the backplane:
    • var connection = System.Configuration.ConfigurationManager.ConnectionStrings["myConnection"].ConnectionString;
  4. Then Enable Service Broker and give proper permisions to the database for the user used in the connection string as it explains further in the documentation.

I’ve added the entire file InitializeSignalR.cs into a Gist

Recompile your code, and you should be all set.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.