Blazor Server exception when using SignalR with AAD authentication

ProgrammerBret 6 Reputation points

I have been working on the issue of a site I am developing in Blazor Server in which I use a signalR chat section in conjunction, and use AAD so I can grab user credentials on the chat section, as well as add the security needed.
This does not work, and produces a json parsing error; so after some more research I was directed to include two projects in the same solution to get around the problem of two SignalR connections in the same project. The new solution has an ASP.NET Core Web app project (for the chat section) and a Blazor Server project (for the AAD connection).
I have set up both projects in VS 2022; However, now am running into some problems -- I reference this SignalR this tutorial and realize there is a javascript file called Chat.js that creates and starts the connection, Adds to the submit button a handler that sends messages to the hub, and Adds to the connection object a handler that receives messages from the hub and adds them to the list. I was hoping to do most the logic for compression middleware and the mapping to the Blazor hub in Program.CS on the Blazor side per this tutorial but confused as which project to use for these functionalities as I try to combine the two projects into one solution.

A set of technologies in the .NET Framework for building web applications and XML web services.
3,774 questions
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,208 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce ( 48,711 Reputation points

    not sure what your issue was with combined server, but I suspect you have only deferred it. be sure you used net 6.

    but in your new solution SignalRChat is the hub (it has some sample pages that use javascript, but you could delete these). The BlazorServerChat should uses the Signal/r client to talk to the hub. you will need to run both web sites.

    on issue you may face. blazor server uses signal/r to communicate with the client browser. this is one connection done at page load, so there is only one authentication done at the connection as the connection stays open. this means any token you get will quickly expire.

    1 person found this answer helpful.
    0 comments No comments