Hope all is well.
I' m trying to implement SignalR in my Blazor server-side app, which also implements Asp.net core identity. I get the following message when I navigate to the razor page that implements the signalr hub:
“HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).”
And the following is highlighted in red for exception:
await hubConnection.StartAsync();
Here is my razor page code behind:
private HubConnection hubConnection;
protected override async Task OnInitializedAsync()
{
hubConnection = new HubConnectionBuilder()
.WithUrl(NavigationManager.ToAbsoluteUri("/EmployeePresenceStatusHub"))
.WithAutomaticReconnect()
.Build();
hubConnection.On("ReceiveMessage", () =>
{
LoadEmployeesPresenceStatus();
StateHasChanged();//Refresh the component using updated data
});
await hubConnection.StartAsync();
}
Here is my hub class:
public class EmpoyeesPresenceStatusHub : Hub
{
public async Task SendMessage()
{
await Clients.All.SendAsync("ReceiveMessage");
}
}
I've followed the example from here:
Use ASP.NET Core SignalR with Blazor
I'm presuming asp.net core identity feature in my Blazor app is causing this?
Any help most appreciated.