Skip to content

Commit

Permalink
Long Polling disabled update (dotnet#23033)
Browse files Browse the repository at this point in the history
  • Loading branch information
guardrex authored Aug 19, 2021
1 parent e320388 commit 873b861
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
31 changes: 31 additions & 0 deletions aspnetcore/blazor/fundamentals/signalr.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,37 @@ When a circuit ends because a user has disconnected and the framework is cleanin

We recommend using the [Azure SignalR Service](xref:signalr/scale#azure-signalr-service) for Blazor Server apps hosted in Microsoft Azure. The service works in conjunction with the app's Blazor Hub for scaling up a Blazor Server app to a large number of concurrent SignalR connections. In addition, the SignalR Service's global reach and high-performance data centers significantly aid in reducing latency due to geography. For prerendering support with the Azure SignalR Service, configure the app to use *sticky sessions*. For more information, see <xref:blazor/host-and-deploy/server>.

## Long Polling

Long Polling was enabled in releases prior to ASP.NET Core 6.0 as a fallback transport for situations in which the WebSockets transport wasn't available. If an app targeting ASP.NET Core 6.0 or later must use Long Polling, make the following changes:

In the app's `Startup.cs` file, replace `endpoints.MapBlazorHub()` with the following code:

```csharp
endpoints.MapBlazorHub(configureOptions: options =>
{
options.Transports =
HttpTransportType.WebSockets | HttpTransportType.LongPolling;
});
```

Add the following script to the `Shared/_Layout.cshtml` file immediately inside the closing `</body>` tag. WebSockets (`1`) and Long Polling (`4`) are the supported `HTTPTransportTypes`. The following example:

* Specifies support for both WebSockets and Long Polling transports (`1 | 4`).
* Defaults to the WebSockets transport when a WebSockets connection can be established.

```html
<script>
(function start() {
Blazor.start({
configureSignalR: builder => builder.withUrl('_blazor', 1 | 4)
});
})()
</script>
```

For more information, see [Disable Long Polling Fallback Transport for Blazor Server (ASP.NET Announcements)](https://github.com/aspnet/Announcements/issues/470).

## Additional resources

* <xref:signalr/introduction>
Expand Down
9 changes: 8 additions & 1 deletion aspnetcore/blazor/host-and-deploy/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ Each circuit uses approximately 250 KB of memory for a minimal *Hello World*-sty

Blazor Server apps use ASP.NET Core SignalR to communicate with the browser. [SignalR's hosting and scaling conditions](xref:signalr/publish-to-azure-web-app) apply to Blazor Server apps.

Blazor works best when using WebSockets as the SignalR transport due to lower latency, reliability, and [security](xref:signalr/security). Long Polling is used by SignalR when WebSockets isn't available or when the app is explicitly configured to use Long Polling. When deploying to Azure App Service, configure the app to use WebSockets in the Azure portal settings for the service. For details on configuring the app for Azure App Service, see the [SignalR publishing guidelines](xref:signalr/publish-to-azure-web-app).
Blazor works best when using WebSockets as the SignalR transport due to lower latency, reliability, and [security](xref:signalr/security). When deploying to Azure App Service, configure the app to use WebSockets in the Azure portal settings for the service. For details on configuring the app for Azure App Service, see the [SignalR publishing guidelines](xref:signalr/publish-to-azure-web-app).

> [!NOTE]
> In releases prior to ASP.NET Core 6.0, Long Polling was enabled as a fallback transport for situations in which the WebSockets transport wasn't available. If an app targeting ASP.NET Core 6.0 or later must use Long Polling, see <xref:blazor/fundamentals/signalr?pivots=server#long-polling>.
>
> For more information, see [Disable Long Polling Fallback Transport for Blazor Server (ASP.NET Announcements)](https://github.com/aspnet/Announcements/issues/470).
#### Azure SignalR Service

Expand All @@ -56,6 +61,8 @@ We recommend using the [Azure SignalR Service](xref:signalr/scale#azure-signalr-
>
> We recommend using WebSockets for Blazor Server apps deployed to Azure App Service. The [Azure SignalR Service](xref:signalr/scale#azure-signalr-service) uses WebSockets by default. If the app doesn't use the Azure SignalR Service, see <xref:signalr/publish-to-azure-web-app#configure-the-app-in-azure-app-service>.
>
> As of the release of ASP.NET Core 6.0, Long Polling isn't enabled by default. For more information, see the [SignalR configuration](#signalr-configuration) section.
>
> For more information, see:
>
> * [What is Azure SignalR Service?](/azure/azure-signalr/signalr-overview)
Expand Down
11 changes: 9 additions & 2 deletions aspnetcore/blazor/security/server/threat-mitigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,17 @@ By default, there's no limit on the number of connections per user for a Blazor
* Require authentication to connect to the app and keep track of the active sessions per user.
* Reject new sessions upon reaching a limit.
* Proxy WebSocket connections to an app through the use of a proxy, such as the [Azure SignalR Service](/azure/azure-signalr/signalr-overview) that multiplexes connections from clients to an app. This provides an app with greater connection capacity than a single client can establish, preventing a client from exhausting the connections to the server.
* At the server level: Use a proxy/gateway in front of the app. For example, [Azure Front Door](/azure/frontdoor/front-door-overview) enables you to define, manage, and monitor the global routing of web traffic to an app and works when Blazor Server apps are configured to use Long Polling.
* At the server level: Use a proxy/gateway in front of the app.

> [!NOTE]
> Although Long Polling is supported for Blazor Server apps, [WebSockets is the recommended transport protocol](xref:blazor/host-and-deploy/server#azure-signalr-service). [Azure Front Door](/azure/frontdoor/front-door-overview) doesn't support WebSockets at this time, but support for WebSockets is under consideration for a future release of the service.
> Long Polling isn't enabled by default for ASP.NET Core 6.0 or later Blazor Server apps. [Azure Front Door](/azure/frontdoor/front-door-overview) doesn't support WebSockets at this time, but support for WebSockets is under consideration for a future release of the service.
>
> For more information, see the following resources:
>
> * <xref:blazor/host-and-deploy/server#signalr-configuration>
> * <xref:blazor/fundamentals/signalr?pivots=server#long-polling>
> * [Disable Long Polling Fallback Transport for Blazor Server (ASP.NET Announcements)](https://github.com/aspnet/Announcements/issues/470)
> * [Support WebSocket connections on Azure Front Door](https://feedback.azure.com/forums/217313-networking/suggestions/37346371-support-websocket-connections-on-azure-front-door)
## Denial of service (DoS) attacks

Expand Down

0 comments on commit 873b861

Please sign in to comment.