Search code examples
signalrsignalr-hubsignalr.clientasp.net-core-signalr

Add headers to @aspnet/signalr Javascript client


I'm using @aspnet/signalr Official Javascript client from This npm package

I wondering if there is the way to add Header configuration to the client connection header

How I build the connection

let connection = new signalR.HubConnectionBuilder() .withUrl( "https://some.signalr-host.com" ) .build();


Solution

  • Update after doing some research

    Seems like signalR js/ts client library doesn't support adding customize headers in anyways

    So, our solution is sending parameters through query string instead and made the server API to support it

    Since signal R URL connection is not shown in the address bar, so it a bit secure

    e.g.

    const connection = new HubConnectionBuilder()
          .withUrl(
            `${signalrUrl}&${key}=${value}`)
          .build();