On an existing Sitecore 8 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 built 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 and before the line
args.App.MapSignalR(Settings.SignalR.Path, new HubConfiguration());
And as for the username, I’ve saved 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 a 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:
- Created a new empty database. The backplane will create the necessary tables in this database.
- Added an extra NuGet package to your application:
- Added the following code to InitializeSignalR.cs to configure the backplane:
var connection = System.Configuration.ConfigurationManager.ConnectionStrings["myConnection"].ConnectionString; GlobalHost.DependencyResolver.UseSqlServer(connection);
- Then Enable Service Broker and give proper permissions 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
|public class InitializeSignalR : InitializeProcessor|
|public override void Process([NotNull] InitializeArgs args)|
|var connection = System.Configuration.ConfigurationManager.ConnectionStrings["myConnection"].ConnectionString;|
|args.App.MapSignalR(Settings.SignalR.Path, new HubConfiguration());|
Recompile your code, and you should be all set.