Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • GianniDPC 14 posts 80 karma points
    Feb 17, 2020 @ 16:26
    GianniDPC
    0

    SignalR in Umbraco 8

    Hello,

    How do I get signalR working in umbraco 8? I followed the tutorial below and it works in a regular MVC .NET Framework application but doesn't with umbraco installed.

    https://docs.microsoft.com/en-us/aspnet/signalr/overview/getting-started/tutorial-getting-started-with-signalr-and-mvc

    I did exactly the same thing when umbraco was installed compared to when it was a simple mvc application. Only thing I needed to do differently was inheriting from UmbracoDefaultOwinStartup.

    So the actual problem with signalR is that I seem to be stuck on the negotiate request. So after a while I get the "Error during negotiation request" message.

    Can someone guide me on how to get it to work? Thanks in advance!

  • Kevin Jump 2348 posts 14896 karma points MVP 8x c-trib
    Feb 17, 2020 @ 17:02
    Kevin Jump
    3

    Hi,

    I'm probably going to end up with a lot of links here, so right up you can see a working v8 signalR sample in the uSync8 code. :

    Js Hub : https://github.com/KevinJump/uSync8/blob/v8/8.2/uSync8.BackOffice/App_Plugins/uSync8/uSyncHub.js

    Controller setup / receive: https://github.com/KevinJump/uSync8/blob/v8/8.2/uSync8.BackOffice/App_Plugins/uSync8/settings/uSyncController.js#L281

    C# Hub : https://github.com/KevinJump/uSync8/blob/v8/8.2/uSync8.BackOffice/Hubs/uSyncHub.cs

    c# Setting up a connection (with a client id usally passed via ApiController) https://github.com/KevinJump/uSync8/blob/d3838708cfeb4ea6599634b86882f8d33c1f169f/uSync8.BackOffice/Hubs/HubClientService.cs

    Logic:

    In terms of special setup, the thing to know is there is already a SignalR hub setup inside Umbraco before you do anything, the url /backoffice/signalr/hubs returns the hub js code that gives you references to any defined hubs and this needs to be loaded before you can do anything in the JS (see the uSyncHub.js). and you can also load the signalR client scripts from /lib/signalr/jquery.signalR.js

    When you start a SignalR hub all the connections are initialized (or reset), but you can't guarantee that your code will be the first to try this, so you should check that things exist before running through the setup (again uSyncHub.js has the logic for this - if you don't do this, you can break things like Umbraco deploy/or preview).

    Back end wise, you need a Hub class to hang your end point off, it doesn't actually need to do anything, but once you have something inheriting the Hub class - the Umbraco signalR script will pick it up.

    In-order to keep messages private a single client and the server you will need to get the clientId in the js. (see the getClientId function here), you can then pass this, and at the other end when you setup the hub connection - passing in the client Id will keep the messages 1-to-1 if you don't pass a clientId it will broadcast the message to all clients (not always a bad thing).

    the main thing was working out what uSyncHub.js needed to do, so looking in there will probably get you most of the way.

  • GianniDPC 14 posts 80 karma points
    Feb 18, 2020 @ 08:42
    GianniDPC
    0

    Can I get this to work without using angular and just javascript? I'm trying to get the chat app to work.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies