Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offline discussion updates for 8.0 #31693

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 1 addition & 5 deletions aspnetcore/blazor/host-and-deploy/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

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

@javiercn Is this warning worded strong enough for you? I remember you complaining about people trying to render <script> tags in triage.

Copy link
Member

Choose a reason for hiding this comment

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

Seems fine to me. The reason for not using script tags in interactive components is clearly stated.


:::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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions aspnetcore/blazor/javascript-interoperability/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
80 changes: 16 additions & 64 deletions aspnetcore/blazor/security/webassembly/additional-scenarios.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;

...

Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand Down
13 changes: 2 additions & 11 deletions aspnetcore/blazor/security/webassembly/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,13 @@ 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:

* 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 the server 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="Client":::** project's component, supply an access token to the hub connection:
* In the client project's component, supply an access token to the hub connection:

```razor
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
Expand All @@ -275,8 +268,6 @@ To secure a SignalR hub:

For more information, see <xref:signalr/authn-and-authz#bearer-token-authentication>.

:::moniker-end

## Logging

*This section applies to Blazor WebAssembly apps in ASP.NET Core 7.0 or later.*
Expand Down
Loading