2

I feel like I'm either missing the point of the SignalR service or I've got the architecture of it wrong.

Using an Azure SignalR service I've got the front-end to front-end communication working as such;

Startup.cs

public void Configuration(IAppBuilder app)
{
    ConfigureAuth(app);
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    app.MapAzureSignalR(this.GetType().FullName);
}

Hub.cs

private void BroadcastMessage(string message)
{
    Clients.All.broadcastMessage(message);
}

Index.html

hubName.client.broadcastMessage = function (message) {
    alert(message);
};

$('#btn').click(function () {
    hubName.server.broadcastMessage("Hello World");
});

This is fine, and when I need the back-end to trigger a message I am using the following;

Functions.cs

HubConnection signalr = new HubConnection("http://localhost:57690/");
IHubProxy hub = null;
if (signalr.State == ConnectionState.Disconnected)
{
    hub = signalr.CreateHubProxy(hubName);
    signalr.Start().Wait();
}
hub.Invoke(functionName, args);
signalr.Stop();

While this works it leaves me wondering if I have implemented it wrong as this leaves http://localhost:57690/signalr/hubs open to posts from any source.

In the front-end, I have to provide the Endpoint=https://appName.service.signalr.net;AccessKey=xxxxx setting but not from the back-end.

As well as a security concern, this leaves me questioning what purpose the SignalR service has in this.

Surely there must be a better way to invoke signalr from the back-end.

Many Thanks,

Tom

  • "but not from the back-end", isn't that everyone wants? It is the same backend application (same OS process), so why do you want access key? I don't see a security concern here. – Lex Li Apr 18 '19 at 16:13

1 Answers1

0

In the Startup.cs you gotta have a line of code like this

services.AddSignalR().AddAzureSignalR();

By not passing a parameter to AddAzureSignalR(), this code uses the default configuration key, Azure:SignalR:ConnectionString, for the SignalR Service resource connection string.

You can find more info in this article

ilkerkaran
  • 4,214
  • 3
  • 27
  • 42
  • I should have been more specific sorry - this is asp.Net 4.7.1 not Core. I think the syntax for Core is `.AddAzureSignalR()` where as the syntax for .net is `.MapAzureSignalR()`. I have my endpoint connection string in the webconfig with the name of `Azure:SignalR:ConnectionString` already which gives me the security on front-end to front-end. – Tom Kirkland Apr 18 '19 at 13:44
  • Actually, your hub is between frontend - frontend. it basically means, your both frontend connects to your hub via the connection string. – ilkerkaran Apr 18 '19 at 13:56