Skip to content

Configure SignalR hub URL endpoint#36769

Open
guardrex wants to merge 1 commit intomainfrom
guardrex/signalr-hub-uri
Open

Configure SignalR hub URL endpoint#36769
guardrex wants to merge 1 commit intomainfrom
guardrex/signalr-hub-uri

Conversation

@guardrex
Copy link
Collaborator

@guardrex guardrex commented Feb 12, 2026

Fixes #36119

Brennan, Wade ...

  • From the issue, it seems that the main problem was just the hub endpoint location config in that scenario. Therefore, I'm angling this addition to the SignalR config article to discuss how to set the URL in code versus statically setting it. I noticed that there isn't an H3 URL configuration section, so that's the first draft on how to add this coverage (and I added it first among the existing H3 sections because it seems to be the most basic among them). If you want to get into more detail on some specific proxy/LB config, then I'll need to know what to cover (and possibly where, since this might move).
  • I use "URL" as opposed to "URI" because the API is named "WithUrl" ... "to use HTTP-based transports to connect to the specified URL and transports."
  • I cross-link from the proxy/LB and Blazor SignalR articles.
  • Removed UseDefaultCredentials because it's covered elsewhere in the article and not necessarily germane to the scenario (let me know if I'm incorrect about that, and I'll add it back).
  • OMG! ... added it to all of the INCLUDES files so that it can be cross-linked from other articles. There's massive content duplication across seven additional files with broken bookmarks in every prior release version of the article. Is the intention to keep going with this to .NET 15 ... .NET 20 (!!!) ... and beyond? I recommend MS stop using this approach for versioning content.

@guardrex guardrex self-assigned this Feb 12, 2026
}.ToString();

hubConnection = new HubConnectionBuilder()
.WithUrl(Navigation.ToAbsoluteUri(uri))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point it is already an absolute URI string I think. Do we need to use Navigation.ToAbsoluteUri() again? Maybe should be just .WithUrl(uri)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took this directly from the PU issue, and it wasn't remarked on there.

It's a string due to the ToString, so I'm thinking this would be better as ...

var uriBuilder = 
    new UriBuilder(Navigation.ToAbsoluteUri("/chathub"))
    { 
        Scheme = "http", Port = 80, Host = ipv4
    };

hubConnection = new HubConnectionBuilder()
    .WithUrl(uriBuilder.Uri,
    config =>
    {
        config.UseDefaultCredentials = true;
    })
    .WithAutomaticReconnect()
.Build();

That way, there's the UriBuilder type, which can then supply a uriBuilder.Uri to WithUrl.

Let's see if Brennan agrees with that change.

var uri =
new UriBuilder(Navigation.ToAbsoluteUri("/chathub"))
{
Scheme = "http", Port = 80, Host = ipv4
Copy link
Contributor

@wadepickett wadepickett Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need a note/context explaining why a hardcoded port and "http" are set here: SignalR hub connection loops back directly to the local IIS server to bypass a load balancer/proxy and avoid the credential problem. I could see folks dropping this code in, as-is with http and Port = 80 without understanding those need to reflect their specific sitaution and why they would use this. They might assume this is a general SignalR URL config guidance as opposed to a specfic workaround.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps, so. I'm 👂 for how deep into the scenario for the example Brennan wants to get.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we end up making the example more generic, we can do it this way with placeholders ...

Scheme = "{SCHEME}", Port = {PORT}, Host = ipv4

@BrennanConroy
Copy link
Member

The original issue is purely a Blazor scenario. There is a HubConnection being created on the server-side that connects back to itself, which is extremely unlikely to happen in applications unless you're using Blazor.

The problem was that the users' setup caused the connection from the HubConnection to fail due to not expecting requests from the backend server. So, the workaround they used was to create a URI that directly went to itself instead of going out to the load balancer.

@guardrex
Copy link
Collaborator Author

guardrex commented Feb 12, 2026

Tomorrow morning, I'll move the coverage to the Blazor SignalR article.

I'll include context in the updated section, and I'll use a more appropriate section header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to implement SignalR Hub on IIS with windows authentification, works fine with IIS Express, negotiate fails 401 !

3 participants