Offline discussion updates for 8.0 (#31693)

pull/31823/head
Luke Latham 2024-02-14 05:58:14 -05:00 committed by GitHub
parent 852b48fe37
commit 3d86df3447
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 69 additions and 105 deletions

View File

@ -398,11 +398,9 @@ The examples in this section focus on supplying the app base path from app setti
* <xref:blazor/fundamentals/configuration>
* <xref:fundamentals/configuration/index>
:::moniker range="< aspnetcore-8.0"
## Blazor Server `MapFallbackToPage` configuration
<!-- UPDATE 8.0 Update for BWAs -->
*This section only applies to Blazor Server apps. <xref:Microsoft.AspNetCore.Builder.RazorPagesEndpointRouteBuilderExtensions.MapFallbackToPage%2A> isn't supported in Blazor Web Apps and Blazor WebAssembly apps.*
In scenarios where an app requires a separate area with custom resources and Razor components:
@ -428,8 +426,6 @@ In scenarios where an app requires a separate area with custom resources and Raz
app.Run();
```
:::moniker-end
:::moniker range="< aspnetcore-8.0"
## Host multiple Blazor WebAssembly apps

View File

@ -1422,11 +1422,20 @@ Using JS modules to load JS is described in this article in the [JavaScript isol
:::moniker-end
<!-- UPDATE 8.0 Confirm for >=8.0 now that the warning is being removed. -->
:::moniker range=">= aspnetcore-8.0"
> [!WARNING]
> Only place a `<script>` tag in a component file (`.razor`) if the component is guaranteed to adopt [static server-side rendering (static SSR)](xref:blazor/fundamentals/index#client-and-server-rendering-concepts) because the `<script>` tag can't be updated dynamically.
:::moniker-end
:::moniker range="< aspnetcore-8.0"
> [!WARNING]
> Don't place a `<script>` tag in a component file (`.razor`) because the `<script>` tag can't be updated dynamically.
:::moniker-end
:::moniker range=">= aspnetcore-5.0"
## JavaScript isolation in JavaScript modules

View File

@ -432,11 +432,20 @@ For information on isolating scripts in [JS modules](https://developer.mozilla.o
:::moniker-end
<!-- UPDATE 8.0 Confirm for >=8.0 now that the warning is being removed. -->
:::moniker range=">= aspnetcore-8.0"
> [!WARNING]
> Only place a `<script>` tag in a component file (`.razor`) if the component is guaranteed to adopt [static server-side rendering (static SSR)](xref:blazor/fundamentals/index#client-and-server-rendering-concepts) because the `<script>` tag can't be updated dynamically.
:::moniker-end
:::moniker range="< aspnetcore-8.0"
> [!WARNING]
> Don't place a `<script>` tag in a component file (`.razor`) because the `<script>` tag can't be updated dynamically.
:::moniker-end
:::moniker range=">= aspnetcore-5.0"
## JavaScript isolation in JavaScript modules

View File

@ -251,10 +251,19 @@ Load JavaScript (JS) code using any of the following approaches:
:::moniker-end
<!-- UPDATE 8.0 Confirm for >=8.0 now that the warning is being removed. -->
:::moniker range=">= aspnetcore-8.0"
> [!WARNING]
> Don't place a `<script>` tag in a Razor component file (`.razor`) because the `<script>` tag can't be updated dynamically by Blazor.
> Only place a `<script>` tag in a component file (`.razor`) if the component is guaranteed to adopt [static server-side rendering (static SSR)](xref:blazor/fundamentals/index#client-and-server-rendering-concepts) because the `<script>` tag can't be updated dynamically.
:::moniker-end
:::moniker range="< aspnetcore-8.0"
> [!WARNING]
> Don't place a `<script>` tag in a component file (`.razor`) because the `<script>` tag can't be updated dynamically.
:::moniker-end
:::moniker range=">= aspnetcore-5.0"

View File

@ -1454,25 +1454,32 @@ If tacking on a segment to the authority isn't appropriate for the app's OIDC pr
The list of claims in the ID token changes for v2.0 endpoints. Microsoft documentation on the changes has been retired, but guidance on the claims in an ID token is available in the [ID token claims reference](/entra/identity-platform/id-token-claims-reference).
:::moniker range="< aspnetcore-8.0"
<!-- UPDATE 8.0 This section was written for hosted WASM.
Check with PU to see if we'll maintain it with mods
in the BWA/WebAssembly world. -->
## Configure and use gRPC in components
To configure a Blazor WebAssembly app to use the [ASP.NET Core gRPC framework](xref:grpc/index):
* Enable gRPC-Web on the server. For more information, see <xref:grpc/grpcweb>.
* Register gRPC services for the app's message handler. The following example configures the app's authorization message handler to use the [`GreeterClient` service from the gRPC tutorial](xref:tutorials/grpc/grpc-start#create-a-grpc-service) (the `Program` file):
* Register gRPC services for the app's message handler. The following example configures the app's authorization message handler to use the [`GreeterClient` service from the gRPC tutorial](xref:tutorials/grpc/grpc-start#create-a-grpc-service) (the `Program` file).
:::moniker range=">= aspnetcore-8.0"
> [!NOTE]
> Prerendering is enabled by default in Blazor Web Apps, so you must account for the component rendering first from the server and then from the client. Any prerendered state should flow to the client so that it can be reused. For more information, see <xref:blazor/components/prerender#persist-prerendered-state>.
:::moniker-end
:::moniker range="< aspnetcore-8.0"
> [!NOTE]
> Prerendering is enabled by default in hosted Blazor WebAssembly apps, so you must account for the component rendering first from the server and then from the client. Any prerendered state should flow to the client so that it can be reused. For more information, see <xref:blazor/components/prerendering-and-integration?pivots=webassembly#persist-prerendered-state>.
:::moniker-end
```csharp
using System.Net.Http;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Grpc.Net.Client;
using Grpc.Net.Client.Web;
using {ASSEMBLY NAME}.Shared;
...
@ -1490,18 +1497,11 @@ builder.Services.AddScoped(sp =>
});
```
The placeholder `{ASSEMBLY NAME}` is the app's assembly name (for example, `BlazorSample`). Place the `.proto` file in the `Shared` project of the hosted Blazor solution.
A component in the client app can make gRPC calls using the gRPC client (`Grpc.razor`):
:::moniker-end
:::moniker range=">= aspnetcore-6.0 < aspnetcore-8.0"
```razor
@page "/grpc"
@using Microsoft.AspNetCore.Authorization
@using {ASSEMBLY NAME}.Shared
@attribute [Authorize]
@inject Greeter.GreeterClient GreeterClient
@ -1536,58 +1536,10 @@ Server response: <strong>@serverResponse</strong>
}
```
:::moniker-end
:::moniker range="< aspnetcore-6.0"
```razor
@page "/grpc"
@using Microsoft.AspNetCore.Authorization
@using {ASSEMBLY NAME}.Shared
@attribute [Authorize]
@inject Greeter.GreeterClient GreeterClient
<h1>Invoke gRPC service</h1>
<p>
<input @bind="name" placeholder="Type your name" />
<button @onclick="GetGreeting" class="btn btn-primary">Call gRPC service</button>
</p>
Server response: <strong>@serverResponse</strong>
@code {
private string name = "Bert";
private string serverResponse;
private async Task GetGreeting()
{
try
{
var request = new HelloRequest { Name = name };
var reply = await GreeterClient.SayHelloAsync(request);
serverResponse = reply.Message;
}
catch (Grpc.Core.RpcException ex)
when (ex.Status.DebugException is
AccessTokenNotAvailableException tokenEx)
{
tokenEx.Redirect();
}
}
}
```
:::moniker-end
:::moniker range="< aspnetcore-8.0"
The placeholder `{ASSEMBLY NAME}` is the app's assembly name (for example, `BlazorSample`). To use the `Status.DebugException` property, use [`Grpc.Net.Client`](https://www.nuget.org/packages/Grpc.Net.Client) version 2.30.0 or later.
To use the `Status.DebugException` property, use [`Grpc.Net.Client`](https://www.nuget.org/packages/Grpc.Net.Client) version 2.30.0 or later.
For more information, see <xref:grpc/grpcweb>.
:::moniker-end
## Replace the `AuthenticationService` implementation
The following subsections explain how to replace:

View File

@ -238,44 +238,33 @@ If Windows Authentication is used with Blazor Webassembly or with any other SPA
For more information, see <xref:security/anti-request-forgery>.
:::moniker range="< aspnetcore-8.0"
<!-- UPDATE 8.0 Versioning out because this applies
directly to hosted WASM. Check with the PU
to confirm no replacement guidance in the
BWA/WebAssembly world -->
## Secure a SignalR hub
To secure a SignalR hub:
To secure a SignalR hub in the server API project, apply the [`[Authorize]` attribute](xref:Microsoft.AspNetCore.Authorization.AuthorizeAttribute) to the hub class or to methods of the hub class.
* In the **:::no-loc text="Server":::** project, apply the [`[Authorize]` attribute](xref:Microsoft.AspNetCore.Authorization.AuthorizeAttribute) to the hub class or to methods of the hub class.
In a client project with prerendering, such as hosted Blazor WebAssembly (ASP.NET Core in .NET 7 or earlier) or a Blazor Web App (ASP.NET Core in .NET 8 or later), see the guidance in <xref:blazor/fundamentals/signalr#client-side-signalr-cross-origin-negotiation-for-authentication>.
* In the **:::no-loc text="Client":::** project's component, supply an access token to the hub connection:
In a client project component without prerendering, such as standalone Blazor WebAssembly, or non-browser apps, supply an access token to the hub connection, as the following example demonstrates. For more information, see <xref:signalr/authn-and-authz#bearer-token-authentication>.
```razor
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@inject IAccessTokenProvider TokenProvider
@inject NavigationManager Navigation
```razor
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@inject IAccessTokenProvider TokenProvider
@inject NavigationManager Navigation
...
var tokenResult = await TokenProvider.RequestAccessToken();
if (tokenResult.TryGetToken(out var token))
{
hubConnection = new HubConnectionBuilder()
.WithUrl(Navigation.ToAbsoluteUri("/chathub"),
options => { options.AccessTokenProvider = () => Task.FromResult(token?.Value); })
.Build();
...
var tokenResult = await TokenProvider.RequestAccessToken();
if (tokenResult.TryGetToken(out var token))
{
hubConnection = new HubConnectionBuilder()
.WithUrl(Navigation.ToAbsoluteUri("/chathub"),
options => { options.AccessTokenProvider = () => Task.FromResult(token?.Value); })
.Build();
...
}
```
For more information, see <xref:signalr/authn-and-authz#bearer-token-authentication>.
:::moniker-end
}
```
## Logging

View File

@ -868,7 +868,7 @@ For detailed guidance on the SignalR and Blazor frameworks, see the following re
## Additional resources
* [Bearer token authentication with Identity Server, WebSockets, and Server-Sent Events](xref:signalr/authn-and-authz#bearer-token-authentication)
* [Secure a SignalR hub in hosted Blazor WebAssembly apps](xref:blazor/security/webassembly/index#secure-a-signalr-hub)
* [Secure a SignalR hub in Blazor WebAssembly apps](xref:blazor/security/webassembly/index#secure-a-signalr-hub)
* [SignalR cross-origin negotiation for authentication](xref:blazor/fundamentals/signalr#client-side-signalr-cross-origin-negotiation-for-authentication)
* [SignalR configuration](xref:blazor/host-and-deploy/server#signalr-configuration)
* <xref:blazor/debug>