Starts in:
2 DAYS
2 HRS
23 MIN
3 SEC
Starts in:
2 D
2 H
23 M
3 S
Open Closed

Issue with SignalR MessagingHub after upgrade to v6.x #4438


User avatar
0
scott7106 created

If you're creating a bug/problem report, please include followings:

  • ABP Framework version: v6.0.3
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no

We are running into an issue after upgrading from ABP v5.3.3 to v6.0.3 with our SignalR implementation. After the upgrade, the CurrentUser property of the messaging hub is not populated with the user context of the authenticated user. CurrentUser.Id is always null. In our case, we only establish the connection to the MessagingHub once the user is authenticated. Prior to the upgrade, this was working as shown.

Any help we can get on this would be appreciated.

[HubRoute("/messaging-hub")]
public class MessagingHub : AbpHub
{
    public readonly static ConnectionMapping _connections = new();
    private readonly IHubContext<MessagingHub> _hubContext;

    public MessagingHub(IHubContext<MessagingHub> hubContext)
    {
        _hubContext = hubContext;
    }
    public override Task OnConnectedAsync()
    {
        if (CurrentUser.Id is not null)
        {
            _connections.Add(
                (Guid)CurrentUser.Id,
                Context.ConnectionId,
                CurrentTenant.Id);
        }

        return base.OnConnectedAsync();
    }

    public override Task OnDisconnectedAsync(Exception exception)
    {
        if (CurrentUser.Id is not null)
        {
            _connections.RemoveConnectionsByUserId((Guid)CurrentUser.Id);
        }

        return base.OnDisconnectedAsync(exception);
    }

    public async Task SendNotificationToUser(Guid userId, AlertMessage message)
    {
        var connections = _connections.GetConnectionsByUserId(userId);
        foreach (var connection in connections)
        {
            await _hubContext.Clients.Client(connection.ConnectionId).SendAsync("NotificationReceived", message);
        }
    }
}

2 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi Can you share a template project to reproduce? liming.ma@volosoft.com

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    The current workaround is to add the access token to the query string when joining connecting to the hub.

    This is the recommended practice.

    The localhost domain will share cookies. But after the application is published it will use a different domain/sub-domain.

    https://learn.microsoft.com/en-us/aspnet/core/signalr/authn-and-authz?view=aspnetcore-7.0#bearer-token-authentication

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06