Blazor WASM configure SignalR client (#18742)
parent
dfeed17ffe
commit
7cf06c1554
|
@ -5,7 +5,7 @@ description: Learn about Blazor hosting model configuration, including how to in
|
|||
monikerRange: '>= aspnetcore-3.1'
|
||||
ms.author: riande
|
||||
ms.custom: mvc
|
||||
ms.date: 05/28/2020
|
||||
ms.date: 06/10/2020
|
||||
no-loc: [Blazor, "Identity", "Let's Encrypt", Razor, SignalR]
|
||||
uid: blazor/hosting-model-configuration
|
||||
---
|
||||
|
@ -281,6 +281,37 @@ For more information on how background updates are handled by PWAs, see <xref:bl
|
|||
|
||||
For information on Blazor WebAssembly logging support, see <xref:fundamentals/logging/index#create-logs-in-blazor>.
|
||||
|
||||
### SignalR cross-origin negotiation for authentication
|
||||
|
||||
To configure SignalR's underlying client to send credentials, such as cookies or HTTP authentication headers:
|
||||
|
||||
* Use <xref:Microsoft.AspNetCore.Components.WebAssembly.Http.WebAssemblyHttpRequestMessageExtensions.SetBrowserRequestCredentials%2A> to set <xref:Microsoft.AspNetCore.Components.WebAssembly.Http.BrowserRequestCredentials.Include> on cross-origin [fetch](https://developer.mozilla.org/docs/Web/API/Fetch_API/Using_Fetch) requests:
|
||||
|
||||
```csharp
|
||||
public class IncludeRequestCredentialsMessagHandler : DelegatingHandler
|
||||
{
|
||||
protected override Task<HttpResponseMessage> SendAsync(
|
||||
HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
request.SetBrowserRequestCredentials(BrowserRequestCredentials.Include);
|
||||
return base.SendAsync(request, cancellationToken);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
* Assign the <xref:System.Net.Http.HttpMessageHandler> to the <xref:Microsoft.AspNetCore.Http.Connections.Client.HttpConnectionOptions.HttpMessageHandlerFactory> option:
|
||||
|
||||
```csharp
|
||||
var client = new HubConnectionBuilder()
|
||||
.WithUrl(new Uri("http://signalr.example.com"), options =>
|
||||
{
|
||||
options.HttpMessageHandlerFactory = innerHandler =>
|
||||
new IncludeRequestCredentialsMessagHandler { InnerHandler = innerHandler };
|
||||
}).Build();
|
||||
```
|
||||
|
||||
For more information, see <xref:signalr/configuration#configure-additional-options>.
|
||||
|
||||
## Blazor Server
|
||||
|
||||
### Reflect the connection state in the UI
|
||||
|
|
|
@ -5,7 +5,7 @@ description: Learn how to build a Blazor-based Progressive Web Application (PWA)
|
|||
monikerRange: '>= aspnetcore-3.1'
|
||||
ms.author: riande
|
||||
ms.custom: mvc
|
||||
ms.date: 06/09/2020
|
||||
ms.date: 06/10/2020
|
||||
no-loc: [Blazor, "Identity", "Let's Encrypt", Razor, SignalR]
|
||||
uid: blazor/progressive-web-app
|
||||
---
|
||||
|
@ -281,3 +281,7 @@ The [CarChecker](https://github.com/SteveSandersonMS/CarChecker) sample app demo
|
|||
* `OfflineAccountClaimsPrincipalFactory` (*Client/Data/OfflineAccountClaimsPrincipalFactory.cs*)
|
||||
* `LocalVehiclesStore` (*Client/Data/LocalVehiclesStore.cs*)
|
||||
* `LoginStatus` component (*Client/Shared/LoginStatus.razor*)
|
||||
|
||||
## Additional resources
|
||||
|
||||
* [SignalR cross-origin negotiation for authentication](xref:blazor/hosting-model-configuration#signalr-cross-origin-negotiation-for-authentication)
|
||||
|
|
|
@ -5,7 +5,7 @@ description: Create a chat app that uses ASP.NET Core SignalR with Blazor WebAss
|
|||
monikerRange: '>= aspnetcore-3.1'
|
||||
ms.author: riande
|
||||
ms.custom: mvc
|
||||
ms.date: 05/19/2020
|
||||
ms.date: 06/10/2020
|
||||
no-loc: [Blazor, "Identity", "Let's Encrypt", Razor, SignalR]
|
||||
uid: tutorials/signalr-blazor-webassembly
|
||||
---
|
||||
|
@ -285,3 +285,4 @@ To learn more about building Blazor apps, see the Blazor documentation:
|
|||
## Additional resources
|
||||
|
||||
* <xref:signalr/introduction>
|
||||
* [SignalR cross-origin negotiation for authentication](xref:blazor/hosting-model-configuration#signalr-cross-origin-negotiation-for-authentication)
|
||||
|
|
Loading…
Reference in New Issue