Reputation: 11
my .NetCore webApp works Perfectly on VS, but when i publish it to IIS, i am getting the following error:
signalr.js:1797 POST http://serverName:8080/TEST/Home/DashboardHub/negotiate?negotiateVersion=1 404 (Not Found) signalr.js:3082 [2023-06-04T13:52:41.790Z] Error: Failed to complete negotiation with the server: Error: Not Found
myHubClient
$(() =>
{
var connection = new signalR.HubConnectionBuilder().withUrl("DashboardHub").build();
connection.start().then(function () {
console.log("Connected...");
});
connection.on("ReceiveProducts", function ()
{
buildProductsTable();
})
});
function buildProductsTable() {
//Call Server
}
StartUp.cs:
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<DashboardHub>("DashboardHub");
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=login}/{id?}");
});
Upvotes: 1
Views: 241
Reputation: 22029
The expect url should be
http://serverName:8080/DashboardHub/negotiate?negotiateVersion=1
After test, I found the issue cause by withUrl("DashboardHub")
. You are missing /
, add it will fix the issue.
My Test Code
"use strict";
var connection = new signalR.HubConnectionBuilder().withUrl(window.location.origin + "/mainHub", { skipNegotiations: true })
.withAutomaticReconnect({
nextRetryDelayInMilliseconds: () => {
this._errorState$.next(true);
return 1000;
},
reconnectDelay: 500 // set the reconnect delay to 500ms
})
.configureLogging(signalR.LogLevel.Debug).build();
connection.serverTimeoutInMilliseconds = 120000;
My Program.cs file
app.MapHub<MainHub>("/mainhub");
My failure Pic , if missing /.
If I use the sample code above, add / it works
Upvotes: 0