Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions aspnetcore/blazor/fundamentals/signalr.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ To resolve the problem, use ***either*** of the following approaches:

* [Secure a SignalR hub](xref:blazor/security/webassembly/index#secure-a-signalr-hub)
* <xref:signalr/introduction>
* <xref:signalr/configuration>
* <xref:signalr/configuration> ([Configure a SignalR hub URL for production](xref:signalr/configuration#configure-the-hub-url-endpoint))
* [Blazor samples GitHub repository (`dotnet/blazor-samples`)](https://github.com/dotnet/blazor-samples) ([how to download](xref:blazor/fundamentals/index#sample-apps))

## Use session affinity (sticky sessions) for server-side web farm hosting
Expand Down Expand Up @@ -1803,7 +1803,7 @@ In the preceding code, `NavManager` is a <xref:Microsoft.AspNetCore.Components.N

* [Server-side host and deployment guidance: SignalR configuration](xref:blazor/host-and-deploy/server/index#signalr-configuration)
* <xref:signalr/introduction>
* <xref:signalr/configuration>
* <xref:signalr/configuration> ([Configure a SignalR hub URL for production](xref:signalr/configuration#configure-the-hub-url-endpoint))
* Server-side security documentation
* <xref:blazor/security/index>
* <xref:blazor/security/index>
Expand Down
2 changes: 2 additions & 0 deletions aspnetcore/host-and-deploy/proxy-load-balancer.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ To display the logs, add `"Microsoft.AspNetCore.HttpLogging": "Information"` to
* <xref:host-and-deploy/web-farm>
* [Microsoft Security Advisory CVE-2018-0787: ASP.NET Core Elevation Of Privilege Vulnerability](https://github.com/aspnet/Announcements/issues/295)
* [YARP: Yet Another Reverse Proxy](https://dotnet.github.io/yarp/)
* [Configure a SignalR hub URL for production](xref:signalr/configuration#configure-the-hub-url-endpoint)

:::moniker-end

Expand Down Expand Up @@ -581,5 +582,6 @@ services.Configure<ForwardedHeadersOptions>(options =>
* <xref:host-and-deploy/web-farm>
* [Microsoft Security Advisory CVE-2018-0787: ASP.NET Core Elevation Of Privilege Vulnerability](https://github.com/aspnet/Announcements/issues/295)
* [YARP: Yet Another Reverse Proxy](https://dotnet.github.io/yarp/)
* [Configure a SignalR hub URL for production](xref:signalr/configuration#configure-the-hub-url-endpoint)

:::moniker-end
41 changes: 39 additions & 2 deletions aspnetcore/signalr/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ description: Learn how to configure ASP.NET Core SignalR apps.
monikerRange: '>= aspnetcore-2.1'
ms.author: wpickett
ms.custom: mvc
ms.date: 05/02/2024
ms.date: 02/12/2026
uid: signalr/configuration
---

# ASP.NET Core SignalR configuration

This article covers ASP.NET Core SignalR configuration.
Expand Down Expand Up @@ -131,6 +130,44 @@ The WebSocket transport has additional options that can be configured using the

Client options can be configured on the `HubConnectionBuilder` type (available in the .NET and JavaScript clients). It's also available in the Java client, but the `HttpHubConnectionBuilder` subclass is what contains the builder configuration options, as well as on the `HubConnection` itself.

### Configure the hub URL endpoint

To set a static hub URL endpoint, pass the URL to <xref:Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderHttpExtensions.WithUrl%2A>. The following example sets the URL to `https://contoso.com/chathub`:

```csharp
var connection = new HubConnectionBuilder()
.WithUrl("https://contoso.com/chathub")
.Build();
```

To configure the endpoint in code, use <xref:System.UriBuilder> to build the URL and pass it to <xref:Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderHttpExtensions.WithUrl%2A>. The following example configures a custom hub URL for production on a target IIS server:

```csharp
#if DEBUG
// IIS Express development environment (development build)
hubConnection = new HubConnectionBuilder()
.WithUrl(Navigation.ToAbsoluteUri("/chathub"))
.WithAutomaticReconnect()
.Build();
#else
// IIS server production environment (release build)
var hostName = Environment.MachineName;
var addresses = Dns.GetHostAddresses(hostName);
var ipv4 = addresses.FirstOrDefault(addresses =>
addresses.AddressFamily == AddressFamily.InterNetwork)?.ToString();
var uri =
new UriBuilder(Navigation.ToAbsoluteUri("/chathub"))
{
Scheme = "http", Port = 80, Host = ipv4
}.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.

.WithAutomaticReconnect()
.Build();
#endif
```

### Configure logging

Logging is configured in the .NET Client using the `ConfigureLogging` method. Logging providers and filters can be registered in the same way as they are on the server. See the [Logging in ASP.NET Core](xref:fundamentals/logging/index) documentation for more information.
Expand Down
38 changes: 38 additions & 0 deletions aspnetcore/signalr/configuration/includes/configuration2.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,44 @@ The WebSocket transport has additional options that can be configured using the

Client options can be configured on the `HubConnectionBuilder` type (available in the .NET and JavaScript clients). It's also available in the Java client, but the `HttpHubConnectionBuilder` subclass is what contains the builder configuration options, as well as on the `HubConnection` itself.

### Configure the hub URL endpoint

To set a static hub URL endpoint, pass the URL to <xref:Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderHttpExtensions.WithUrl%2A>. The following example sets the URL to `https://contoso.com/chathub`:

```csharp
var connection = new HubConnectionBuilder()
.WithUrl("https://contoso.com/chathub")
.Build();
```

To configure the endpoint in code, use <xref:System.UriBuilder> to build the URL and pass it to <xref:Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderHttpExtensions.WithUrl%2A>. The following example configures a custom hub URL for production on a target IIS server:

```csharp
#if DEBUG
// IIS Express development environment (development build)
hubConnection = new HubConnectionBuilder()
.WithUrl(Navigation.ToAbsoluteUri("/chathub"))
.WithAutomaticReconnect()
.Build();
#else
// IIS server production environment (release build)
var hostName = Environment.MachineName;
var addresses = Dns.GetHostAddresses(hostName);
var ipv4 = addresses.FirstOrDefault(addresses =>
addresses.AddressFamily == AddressFamily.InterNetwork)?.ToString();
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

}.ToString();

hubConnection = new HubConnectionBuilder()
.WithUrl(Navigation.ToAbsoluteUri(uri))
.WithAutomaticReconnect()
.Build();
#endif
```

### Configure logging

Logging is configured in the .NET Client using the `ConfigureLogging` method. Logging providers and filters can be registered in the same way as they are on the server. See the [Logging in ASP.NET Core](xref:fundamentals/logging/index) documentation for more information.
Expand Down
38 changes: 38 additions & 0 deletions aspnetcore/signalr/configuration/includes/configuration2.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,44 @@ The WebSocket transport has additional options that can be configured using the

Client options can be configured on the `HubConnectionBuilder` type (available in the .NET and JavaScript clients). It's also available in the Java client, but the `HttpHubConnectionBuilder` subclass is what contains the builder configuration options, as well as on the `HubConnection` itself.

### Configure the hub URL endpoint

To set a static hub URL endpoint, pass the URL to <xref:Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderHttpExtensions.WithUrl%2A>. The following example sets the URL to `https://contoso.com/chathub`:

```csharp
var connection = new HubConnectionBuilder()
.WithUrl("https://contoso.com/chathub")
.Build();
```

To configure the endpoint in code, use <xref:System.UriBuilder> to build the URL and pass it to <xref:Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderHttpExtensions.WithUrl%2A>. The following example configures a custom hub URL for production on a target IIS server:

```csharp
#if DEBUG
// IIS Express development environment (development build)
hubConnection = new HubConnectionBuilder()
.WithUrl(Navigation.ToAbsoluteUri("/chathub"))
.WithAutomaticReconnect()
.Build();
#else
// IIS server production environment (release build)
var hostName = Environment.MachineName;
var addresses = Dns.GetHostAddresses(hostName);
var ipv4 = addresses.FirstOrDefault(addresses =>
addresses.AddressFamily == AddressFamily.InterNetwork)?.ToString();
var uri =
new UriBuilder(Navigation.ToAbsoluteUri("/chathub"))
{
Scheme = "http", Port = 80, Host = ipv4
}.ToString();

hubConnection = new HubConnectionBuilder()
.WithUrl(Navigation.ToAbsoluteUri(uri))
.WithAutomaticReconnect()
.Build();
#endif
```

### Configure logging

Logging is configured in the .NET Client using the `ConfigureLogging` method. Logging providers and filters can be registered in the same way as they are on the server. See the [Logging in ASP.NET Core](xref:fundamentals/logging/index) documentation for more information.
Expand Down
38 changes: 38 additions & 0 deletions aspnetcore/signalr/configuration/includes/configuration3.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,44 @@ The WebSocket transport has additional options that can be configured using the

Client options can be configured on the `HubConnectionBuilder` type (available in the .NET and JavaScript clients). It's also available in the Java client, but the `HttpHubConnectionBuilder` subclass is what contains the builder configuration options, as well as on the `HubConnection` itself.

### Configure the hub URL endpoint

To set a static hub URL endpoint, pass the URL to <xref:Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderHttpExtensions.WithUrl%2A>. The following example sets the URL to `https://contoso.com/chathub`:

```csharp
var connection = new HubConnectionBuilder()
.WithUrl("https://contoso.com/chathub")
.Build();
```

To configure the endpoint in code, use <xref:System.UriBuilder> to build the URL and pass it to <xref:Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderHttpExtensions.WithUrl%2A>. The following example configures a custom hub URL for production on a target IIS server:

```csharp
#if DEBUG
// IIS Express development environment (development build)
hubConnection = new HubConnectionBuilder()
.WithUrl(Navigation.ToAbsoluteUri("/chathub"))
.WithAutomaticReconnect()
.Build();
#else
// IIS server production environment (release build)
var hostName = Environment.MachineName;
var addresses = Dns.GetHostAddresses(hostName);
var ipv4 = addresses.FirstOrDefault(addresses =>
addresses.AddressFamily == AddressFamily.InterNetwork)?.ToString();
var uri =
new UriBuilder(Navigation.ToAbsoluteUri("/chathub"))
{
Scheme = "http", Port = 80, Host = ipv4
}.ToString();

hubConnection = new HubConnectionBuilder()
.WithUrl(Navigation.ToAbsoluteUri(uri))
.WithAutomaticReconnect()
.Build();
#endif
```

### Configure logging

Logging is configured in the .NET Client using the `ConfigureLogging` method. Logging providers and filters can be registered in the same way as they are on the server. See the [Logging in ASP.NET Core](xref:fundamentals/logging/index) documentation for more information.
Expand Down
38 changes: 38 additions & 0 deletions aspnetcore/signalr/configuration/includes/configuration3.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,44 @@ The WebSocket transport has additional options that can be configured using the

Client options can be configured on the `HubConnectionBuilder` type (available in the .NET and JavaScript clients). It's also available in the Java client, but the `HttpHubConnectionBuilder` subclass is what contains the builder configuration options, as well as on the `HubConnection` itself.

### Configure the hub URL endpoint

To set a static hub URL endpoint, pass the URL to <xref:Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderHttpExtensions.WithUrl%2A>. The following example sets the URL to `https://contoso.com/chathub`:

```csharp
var connection = new HubConnectionBuilder()
.WithUrl("https://contoso.com/chathub")
.Build();
```

To configure the endpoint in code, use <xref:System.UriBuilder> to build the URL and pass it to <xref:Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderHttpExtensions.WithUrl%2A>. The following example configures a custom hub URL for production on a target IIS server:

```csharp
#if DEBUG
// IIS Express development environment (development build)
hubConnection = new HubConnectionBuilder()
.WithUrl(Navigation.ToAbsoluteUri("/chathub"))
.WithAutomaticReconnect()
.Build();
#else
// IIS server production environment (release build)
var hostName = Environment.MachineName;
var addresses = Dns.GetHostAddresses(hostName);
var ipv4 = addresses.FirstOrDefault(addresses =>
addresses.AddressFamily == AddressFamily.InterNetwork)?.ToString();
var uri =
new UriBuilder(Navigation.ToAbsoluteUri("/chathub"))
{
Scheme = "http", Port = 80, Host = ipv4
}.ToString();

hubConnection = new HubConnectionBuilder()
.WithUrl(Navigation.ToAbsoluteUri(uri))
.WithAutomaticReconnect()
.Build();
#endif
```

### Configure logging

Logging is configured in the .NET Client using the `ConfigureLogging` method. Logging providers and filters can be registered in the same way as they are on the server. See the [Logging in ASP.NET Core](xref:fundamentals/logging/index) documentation for more information.
Expand Down
38 changes: 38 additions & 0 deletions aspnetcore/signalr/configuration/includes/configuration5.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,44 @@ The WebSocket transport has additional options that can be configured using the

Client options can be configured on the `HubConnectionBuilder` type (available in the .NET and JavaScript clients). It's also available in the Java client, but the `HttpHubConnectionBuilder` subclass is what contains the builder configuration options, as well as on the `HubConnection` itself.

### Configure the hub URL endpoint

To set a static hub URL endpoint, pass the URL to <xref:Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderHttpExtensions.WithUrl%2A>. The following example sets the URL to `https://contoso.com/chathub`:

```csharp
var connection = new HubConnectionBuilder()
.WithUrl("https://contoso.com/chathub")
.Build();
```

To configure the endpoint in code, use <xref:System.UriBuilder> to build the URL and pass it to <xref:Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderHttpExtensions.WithUrl%2A>. The following example configures a custom hub URL for production on a target IIS server:

```csharp
#if DEBUG
// IIS Express development environment (development build)
hubConnection = new HubConnectionBuilder()
.WithUrl(Navigation.ToAbsoluteUri("/chathub"))
.WithAutomaticReconnect()
.Build();
#else
// IIS server production environment (release build)
var hostName = Environment.MachineName;
var addresses = Dns.GetHostAddresses(hostName);
var ipv4 = addresses.FirstOrDefault(addresses =>
addresses.AddressFamily == AddressFamily.InterNetwork)?.ToString();
var uri =
new UriBuilder(Navigation.ToAbsoluteUri("/chathub"))
{
Scheme = "http", Port = 80, Host = ipv4
}.ToString();

hubConnection = new HubConnectionBuilder()
.WithUrl(Navigation.ToAbsoluteUri(uri))
.WithAutomaticReconnect()
.Build();
#endif
```

### Configure logging

Logging is configured in the .NET Client using the `ConfigureLogging` method. Logging providers and filters can be registered in the same way as they are on the server. See the [Logging in ASP.NET Core](xref:fundamentals/logging/index) documentation for more information.
Expand Down
38 changes: 38 additions & 0 deletions aspnetcore/signalr/configuration/includes/configuration6.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,44 @@ The WebSocket transport has additional options that can be configured using the

Client options can be configured on the `HubConnectionBuilder` type (available in the .NET and JavaScript clients). It's also available in the Java client, but the `HttpHubConnectionBuilder` subclass is what contains the builder configuration options, as well as on the `HubConnection` itself.

### Configure the hub URL endpoint

To set a static hub URL endpoint, pass the URL to <xref:Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderHttpExtensions.WithUrl%2A>. The following example sets the URL to `https://contoso.com/chathub`:

```csharp
var connection = new HubConnectionBuilder()
.WithUrl("https://contoso.com/chathub")
.Build();
```

To configure the endpoint in code, use <xref:System.UriBuilder> to build the URL and pass it to <xref:Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderHttpExtensions.WithUrl%2A>. The following example configures a custom hub URL for production on a target IIS server:

```csharp
#if DEBUG
// IIS Express development environment (development build)
hubConnection = new HubConnectionBuilder()
.WithUrl(Navigation.ToAbsoluteUri("/chathub"))
.WithAutomaticReconnect()
.Build();
#else
// IIS server production environment (release build)
var hostName = Environment.MachineName;
var addresses = Dns.GetHostAddresses(hostName);
var ipv4 = addresses.FirstOrDefault(addresses =>
addresses.AddressFamily == AddressFamily.InterNetwork)?.ToString();
var uri =
new UriBuilder(Navigation.ToAbsoluteUri("/chathub"))
{
Scheme = "http", Port = 80, Host = ipv4
}.ToString();

hubConnection = new HubConnectionBuilder()
.WithUrl(Navigation.ToAbsoluteUri(uri))
.WithAutomaticReconnect()
.Build();
#endif
```

### Configure logging

Logging is configured in the .NET Client using the `ConfigureLogging` method. Logging providers and filters can be registered in the same way as they are on the server. See the [Logging in ASP.NET Core](xref:fundamentals/logging/index) documentation for more information.
Expand Down
Loading