© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
9 replies
Bordin

✅ SignalR Authorized Connection

namespace LebUpwork.Api.Hubs
{
    //[Authorize] <- This causes error when connecting 
    public class NotificationHub : Hub<INotification>
    {
        public override async Task OnConnectedAsync()
        {
           await Clients.Client(Context.ConnectionId).ReceiveNotification($"Thank you for connecting {Context.User?.Identity.Name}");
           await base.OnConnectedAsync();
        }
    }
    
}
namespace LebUpwork.Api.Hubs
{
    //[Authorize] <- This causes error when connecting 
    public class NotificationHub : Hub<INotification>
    {
        public override async Task OnConnectedAsync()
        {
           await Clients.Client(Context.ConnectionId).ReceiveNotification($"Thank you for connecting {Context.User?.Identity.Name}");
           await base.OnConnectedAsync();
        }
    }
    
}

hello, i am initiating a connection on this Hub, however when i add [Authorized] the connection is failing
const connection = new HubConnectionBuilder()
        .withUrl("https://localhost:7170/Hubs/NotificationHub", {
          accessTokenFactory: () => token,
          skipNegotiation: true,
          transport: HttpTransportType.WebSockets,
        })
        .build();
const connection = new HubConnectionBuilder()
        .withUrl("https://localhost:7170/Hubs/NotificationHub", {
          accessTokenFactory: () => token,
          skipNegotiation: true,
          transport: HttpTransportType.WebSockets,
        })
        .build();

even tho I am adding the accessTokenFactory. Am i doing something wrong?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

SignalR ConnectionManager Singleton
C#CC# / help
4y ago
✅ SignalR Websocket Connection failed
C#CC# / help
4y ago
✅ SignalR getting connectionID from userID
C#CC# / help
3mo ago