Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 7025

Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 2162

Deprecated: Hook imagify_allow_picture_tags_for_webp is deprecated since version 2.2! Use imagify_allow_picture_tags_for_nextgen instead. in /www/collab365_296/public/wp-includes/functions.php on line 5758
Using SignalR 2.2 in a SharePoint 2013 farm solution - Collab365
Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Warning: Undefined array key "url" in /www/collab365_296/public/wp-content/plugins/thrive-visual-editor/thrive-dashboard/inc/smart-site/classes/class-tvd-smart-shortcodes.php on line 85

2015-01-26

In order to properly integrate SignalR with a SharePoint 2013 farm solution you have to make two types of changes to the typical SignalR boilerplate code: Change the Startup.cs and make a couple of web.config modifications.

Please note that this sample assumes that you are using SignalR 2.2, which in turn references OWin 2.1. In case you are using a newer version, make sure to adapt the assembly version numbers in the code snippets below accordingly (Version=2.1.0.0).

Startup.cs class

Add the DefaultAssemblyLocator to your Startup.cs, it is needed to locate and load your hub class in SharePoint:

GlobalHost.DependencyResolver.Register(typeof(IAssemblyLocator),() => new DefaultAssemblyLocator());

A sample Startup.cs would look like this:

public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
GlobalHost.DependencyResolver.Register(typeof(IAssemblyLocator),() => new DefaultAssemblyLocator());
 }
 }

SharePoint web.config modifications

In your web.config, make the following changes (use SPWebConfigModification for a proper deployment):

a) App settings

<appSettings>
(…)
<add key="owin:appStartup" value="YourNamespace.YourNameOfStartupClass, YourDllName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=XXX" />
<add key="owin:AutomaticAppStartup" value="true" />
</appSettings>

b) Add the OWin handler, so that the hub path is handled by Owin/SignalR (e.g. “/signalr/hubs”)

c) Remove or comment the “ExtensionlessUrl” entries in the handlers section. This is needed so that IIS can handle the hub path at all (e.g. “/signalr/hubs”)

<handlers>
(…) 
<add name="Owin" verb="*" path="/signalr" type="Microsoft.Owin.Host.SystemWeb.OwinHttpHandler, Microsoft.Owin.Host.SystemWeb, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<!-- remove name="ExtensionlessUrl-ISAPI-4.0_64bit" / -->
<!-- remove name="ExtensionlessUrl-ISAPI-4.0_32bit" / -->
(…) 
</handlers>

d) Change the legacyCasModel to FALSE

<trust level="Full" originUrl="" legacyCasModel="false" />

e) Optional: If there is already a version of OWin installed, make sure to also add an assembly binding redirect to load the new versions:

<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>

Final points

Verify in your application page or custom web part that the order of the JavaScript includes is as follows:

<script src="Scripts/jquery-1.8.2.min.js" ></script>
<script src="Scripts/jquery.signalR-2.2.0.min.js"></script>
<script src="/signalr/hubs"></script>

…and you are good to go!

Alternative

An alternative Approach would be to generate the JavaScript file once. Look in the SignalrR docs for “How to create a physical file for the SignalR generated Proxy”.

*** This post has been originally posted on my blog ***

(Visited 250 times, 1 visits today)

About the author 

Oliver Pistor

Summit Bundle

Get 200+ hours of Microsoft 365 Training for 27$!

Master Office 365, Power Platform & SharePoint & Teams With 200+ Hours Of Training Videos and 108 Ebooks in the Collab365 Academy. This offer is insane and is only available for a limited period.