Skip to content

2.0.0

Compare
Choose a tag to compare
@davidfowl davidfowl released this 20 Sep 19:05

Overview

Ability to send to a User

This feature allows users to specify what the userId is based on an IRequest via a new interface IUserIdProvider:

public interface IUserIdProvider
{
    string GetUserId(IRequest request);
}

By default there will be an implementation that uses the user's IPrincipal.Identity.Name as the user name.

In hubs, you'll be able to send messages to these users via a new API:

public class MyHub : Hub
{
    public void Send(string userId, string message)
    {
        Clients.User(userId).send(message);
    }
}

Better Error handling support

Users can now throw HubException from any hub invocation. The constructor of the HubException can take a string message and an object extra error data. SignalR will auto-serialize the exception and send it to the client where it will be used to reject/fail the hub method invocation.

The show detailed hub exceptions setting has no bearing on HubException being sent back to the client or not; it always is.

Server

public class MyHub : Hub
{
    public void Send(string message)
    {
        if(message.Contains("<script>"))
        {
            throw new HubException("This message will flow to the client", new { user = Context.User.Identity.Name, message = message });
        }

        Clients.All.send(message);
    }
}

JS Client

myHub.server.send("<script>")
            .fail(function (e) {
                if (e.source === 'HubException') {
                    console.log(e.message + ' : ' + e.data.user);
                }
            });

.NET Client

try
{
    await myHub.Invoke("Send", "<script>");
}
catch(HubException ex)
{
    Conosle.WriteLine(ex.Message);
}

Features

  • Add ability to send a message to a "user" (#2401)
  • Add HubException that always flows back to hub clients (#2376)
  • Allow easy filtering of exception in the Hub Pipeline Module (#1882)

Bugs Fixed

  • Add .NET servicing attribute to all assemblies (#2444)
  • typo in Abort connection log message (#2404)
  • Closing Firefox/Opera tab does not trigger OnDisconnected event (#2400)
  • Fix description and dependencies of nuget package SignalR.SelfHost (#2384)
  • Update README files for WebHost and SelfHost (#2383)
  • GlobalHost.Configuration.XX should display their default value on Intellisense (#2370)
  • Self-hosted SignalR client calls fail after start.done() for a short duration (#2358)
  • DebugTextWriter on Portable causes each character to be written on its own line (#2321)
  • 2.0.0-beta2 - takes 2 minutes for client to call server (#2306)
  • Version SignalR 2.0.0-beta2 Could not load type... error! (#2242)
  • Scaleout - ServiceBus: No tracing with incorrect connection string (#2211)
  • JS client immediately start->stop->start connection, the first deferred.done is also triggered (#2189)