How to pass headers to signalr hub using typescript client (Signalr Core)

Discussão em 'Angular' iniciado por John Code, Março 5, 2025.

  1. John Code

    John Code Guest

    I want to pass a header through my Hubconnection builder to my signalrHub. In other words, how do I accomplish this Using typescript.

    Here is the C# implementation I have:

    connection = new HubConnectionBuilder()
    .WithUrl("https://localhost:53251" + "/simpleHub", options =>
    {
    //set the header
    options.Headers.Add("Device-ID", deviceID);
    })
    .Build();


    How can I do the same with typescript client ? I tried several things I found online, the latest was :

    this._hubConnection = new HubConnectionBuilder()
    .withUrl("https://localhost:53251" + "/simpleHub?Device-ID=fc8dsc72f-1456-4bc2-b1ea-ac34b9c3559e", {
    })
    .configureLogging(LogLevel.Debug)
    .withAutomaticReconnect()
    .build();


    But Passing the header this way, causes the server not to receive the header. Please does anyone have a solution ? please.

    Continue reading...

Compartilhe esta Página