Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR and Sitecore

Does anybody have SignalR and Sitecore working together?

There is an issue in Sitecore with hitting the Application_Start in Sitecore and getting it to kickoff RouteTable.Routes.MapHubs().

I have double checked that I am mapping to my URL/signalR/hubs default on the layouts. The script blocks for JQuery, JQuery SignalR, and the custom JS are also included.

It pulls everything down fine on the Client Side, except that the URL/signalr/hubs is not mapping.

I have noticed some special handling needed in Sitecore for MVC RouteTables, but these do not directly address the issue currently experienced.

Thanks -

like image 738
Jeremy Avatar asked Nov 24 '25 14:11

Jeremy


2 Answers

So after so working on this for a bit...

It was the simple thing that makes this work.

You have to add the /signalr and /signalr/hubs to the Ignore Path for SignalR to work with Sitecore.

<setting name="IgnoreUrlPrefixes"                value="/sitecore/default.aspx|/trace.axd|.....|/signalr|/signalr/hubs" />

After I got that into place, I was able to see the MapHubs wire up correctly in the Application_Start. It would not consistently hit the break point before since it couldn't provide the URL without trying to get a Sitecore item. Now I see it hit the breakpoint consistently.

Thanks for the responses!

like image 113
Jeremy Avatar answered Nov 28 '25 02:11

Jeremy


I'm assuming that you are using Sitecore 6.6 as you've mentioned the Sitecore MVC RouteTables. Try using WebActivator to register your hub mappings in the RouteTable. WebActivator gives you options to add this bootstrap code into either a PreApplicationStartMethod or a PostApplicationStartMethod so that you can register your routes and avoid Sitecore's wildcard route taking precedence. I have used this approach to bootstrap Web API routes under Sitecore.

using System;

[assembly: WebActivator.PreApplicationStartMethod(
    typeof($rootnamespace$.App_Start.MySuperPackage), "PreStart")]

namespace $rootnamespace$.App_Start {
    public static class MySuperPackage {
        public static void PreStart() {
            // Add your start logic here
        }
    }
}

An alternative approach would be to add the registration code into a custom pipeline processor and add this processor into the initialize event pipeline in App_Config\Include\Sitecore.Mvc.config

<pipelines>

  <!-- Loader -->

  <initialize>
    <processor type="Sitecore.Mvc.Pipelines.Loader.InitializeGlobalFilters, Sitecore.Mvc"/>
    <processor type="Sitecore.Mvc.Pipelines.Loader.InitializeControllerFactory, Sitecore.Mvc"/>
    <processor type="Sitecore.Mvc.Pipelines.Loader.InitializeRoutes, Sitecore.Mvc"/>
  </initialize>
like image 38
Kevin Obee Avatar answered Nov 28 '25 04:11

Kevin Obee