David Ash
David Ash

Reputation: 11

.NetCore SignalR works in IIS Express but Not IIS - failing with Negotiate 404 error

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

Answers (1)

Jason Pan
Jason Pan

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 /.

enter image description here

If I use the sample code above, add / it works

enter image description here

Upvotes: 0

Related Questions