I am currently trying to use Azure SignalR in my Blazor app but I am currently experiencing difficulties which what looks like authentication errors.
I have set it up in my Program.cs
file to include the Azure SignalR:
builder.Services.AddSignalR().AddAzureSignalR();
I have then added my connection string into the appsettings.json
which is validated as when running the application I get the following message:
Hub is now connected to '(Primary)xxx.service.signalr.net')
I have mapped my hub within my Program.cs
app.MapHub<MessageHub>('/messagehub');
However when I try to connect to the hub I get the following issue:
Invalid negotiation response received.
I believe this to be me having authentication within my application and this error is being produced as a result of an unauthenticated error.
However, how can I authenticate with Azure and use that hub?
CodePudding user response:
I have followed the MSDOC to use Azure SignalR services in Blazor App.
I hope you followed the same way. If not follow the below workaround
use latest Microsoft.Azure.SignalR package in your application
I have added the connection string of azure SignalR in a appsettings.json
file
"Azure": {
"SignalR": {
"Enabled": true,
"ConnectionString": "<SignalR Connection String>"
}
},
# use ServerStickyMode to avoid Inconsistent UI state management. If you are using many servers
"Azure:SignalR:ServerStickyMode": "Required"
I am using endpoints to Map the Hub.
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/Fallback page");
endpoints.MapHub<YourHub>('/YourHub');
});
Add the Azure SignalR service in a ConfigureServices
public void ConfigureServices(IServiceCollection services) {
services.AddSignalR().AddAzureSignalR();
...
}
After configuring these you can be able to authenticate your hub.
If still facing issue add the below line of code in your ConfigureServices to know the detailed error.
services.AddSignalR(
s =>
{
s.EnableDetailedErrors = true;
});
Refer SO thread for similar kind of issue