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

Merge to Live #32885

Merged
merged 2 commits into from
Jun 19, 2024
Merged
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: 1 addition & 3 deletions aspnetcore/blazor/components/quickgrid.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ Start by adding a package reference for the [`Microsoft.AspNetCore.Components.Qu

[!INCLUDE[](~/includes/package-reference.md)]

<!-- UPDATE 8.0 MIA API for AddQuickGridEntityFrameworkAdapter -->

Call `AddQuickGridEntityFrameworkAdapter` on the service collection in the `Program` file to register an EF-aware <xref:Microsoft.AspNetCore.Components.QuickGrid.IAsyncQueryExecutor> implementation:
Call <xref:Microsoft.Extensions.DependencyInjection.EntityFrameworkAdapterServiceCollectionExtensions.AddQuickGridEntityFrameworkAdapter%2A> on the service collection in the `Program` file to register an EF-aware <xref:Microsoft.AspNetCore.Components.QuickGrid.IAsyncQueryExecutor> implementation:

```csharp
builder.Services.AddQuickGridEntityFrameworkAdapter();
Expand Down
2 changes: 0 additions & 2 deletions aspnetcore/blazor/fundamentals/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -1696,8 +1696,6 @@ A Blazor Web App is integrated into [ASP.NET Core Endpoint Routing](xref:fundame
app.MapRazorComponents<App>();
```

<!-- UPDATE 8.0 Any additional remarks for BWAs? -->

:::moniker-end

:::moniker range=">= aspnetcore-6.0 < aspnetcore-8.0"
Expand Down
14 changes: 14 additions & 0 deletions aspnetcore/blazor/host-and-deploy/configure-trimmer.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Blazor WebAssembly performs [Intermediate Language (IL)](/dotnet/standard/glossa

Trimming may have detrimental effects for the published app. In apps that use [reflection](/dotnet/csharp/advanced-topics/reflection-and-attributes/), the IL Trimmer often can't determine the required types for runtime reflection and trim them away. For example, complex framework types for JS interop, such as <xref:System.Collections.Generic.KeyValuePair>, might be trimmed by default and not available at runtime for JS interop calls. In these cases, we recommend creating your own custom types instead. The IL Trimmer is also unable to react to an app's dynamic behavior at runtime. To ensure the trimmed app works correctly once deployed, test published output frequently while developing.

## Configuration

To configure the IL Trimmer, see the [Trimming options](/dotnet/core/deploying/trimming/trimming-options) article in the .NET Fundamentals documentation, which includes guidance on the following subjects:

* Disable trimming for the entire app with the `<PublishTrimmed>` property in the project file.
Expand All @@ -28,6 +30,18 @@ To configure the IL Trimmer, see the [Trimming options](/dotnet/core/deploying/t
* Control symbol trimming and debugger support.
* Set IL Trimmer features for trimming framework library features.

## Default trimmer granularity

The default trimmer granularity for Blazor apps is `partial`. To trim all assemblies, change the granularity to `full` in the app's project file:

```xml
<ItemGroup>
<TrimMode>full</TrimMode>
</ItemGroup>
```

For more information, see [Trimming options (.NET documentation)](/dotnet/core/deploying/trimming/trimming-options#trimming-granularity).

## Additional resources

* [Trim self-contained deployments and executables](/dotnet/core/deploying/trimming/trim-self-contained)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,6 @@ For more information, see <xref:security/cross-site-scripting>.

Cross-origin attacks involve a client from a different origin performing an action against the server. The malicious action is typically a GET request or a form POST (Cross-Site Request Forgery, CSRF), but opening a malicious WebSocket is also possible. Blazor apps offer [the same guarantees that any other SignalR app using the hub protocol offer](xref:signalr/security):

<!-- UPDATE 8.0 Flesh out the 2nd bullet for DisableCorsAttribute -->

* Apps can be accessed cross-origin unless additional measures are taken to prevent it. To disable cross-origin access, either disable CORS in the endpoint by adding the CORS Middleware to the pipeline and adding the <xref:Microsoft.AspNetCore.Cors.DisableCorsAttribute> to the Blazor endpoint metadata or limit the set of allowed origins by [configuring SignalR for Cross-Origin Resource Sharing](xref:signalr/security#cross-origin-resource-sharing). For guidance on WebSocket origin restrictions, see <xref:fundamentals/websockets#websocket-origin-restriction>.
* If CORS is enabled, extra steps might be required to protect the app depending on the CORS configuration. If CORS is globally enabled, CORS can be disabled for the Blazor SignalR hub by adding the <xref:Microsoft.AspNetCore.Cors.DisableCorsAttribute> metadata to the endpoint metadata after calling <xref:Microsoft.AspNetCore.Builder.ComponentEndpointRouteBuilderExtensions.MapBlazorHub%2A> on the endpoint route builder.

Expand Down
32 changes: 15 additions & 17 deletions aspnetcore/migration/70-80.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ In the project file, update each [`Microsoft.AspNetCore.*`](https://www.nuget.or

## Blazor

<!-- UPDATE 8.0 Add API cross-links after RTM -->

The following migration scenarios are covered:

* [Update a Blazor Server app](#update-a-blazor-server-app)
Expand Down Expand Up @@ -166,7 +164,7 @@ Blazor Server apps are supported in .NET 8 without any code changes. Use the fol
+ <base href="/" />
```

Remove the Component Tag Helper for the `HeadOutlet` component and replace it with the `HeadOutlet` component.
Remove the Component Tag Helper for the <xref:Microsoft.AspNetCore.Components.Web.HeadOutlet> component and replace it with the <xref:Microsoft.AspNetCore.Components.Web.HeadOutlet> component.

Remove the following line:

Expand Down Expand Up @@ -247,15 +245,15 @@ Blazor Server apps are supported in .NET 8 without any code changes. Use the fol
using BlazorServerApp;
```

Replace `AddServerSideBlazor` with `AddRazorComponents` and a chained call to `AddInteractiveServerComponents`.
Replace <xref:Microsoft.Extensions.DependencyInjection.ComponentServiceCollectionExtensions.AddServerSideBlazor%2A> with <xref:Microsoft.Extensions.DependencyInjection.RazorComponentsServiceCollectionExtensions.AddRazorComponents%2A> and a chained call to <xref:Microsoft.Extensions.DependencyInjection.ServerRazorComponentsBuilderExtensions.AddInteractiveServerComponents%2A>.

Remove the following line:

```diff
- builder.Services.AddServerSideBlazor();
```

Replace the preceding line with Razor component and interactive server component services. Calling `AddRazorComponents` adds antiforgery services (`AddAntiforgery`) by default.
Replace the preceding line with Razor component and interactive server component services. Calling <xref:Microsoft.Extensions.DependencyInjection.RazorComponentsServiceCollectionExtensions.AddRazorComponents%2A> adds antiforgery services (<xref:Microsoft.Extensions.DependencyInjection.AntiforgeryServiceCollectionExtensions.AddAntiforgery%2A>) by default.

```csharp
builder.Services.AddRazorComponents()
Expand All @@ -268,7 +266,7 @@ Blazor Server apps are supported in .NET 8 without any code changes. Use the fol
- app.MapBlazorHub();
```

Replace the preceding line with a call to `MapRazorComponents`, supplying the `App` component as the root component type, and add a chained call to `AddInteractiveServerRenderMode`:
Replace the preceding line with a call to <xref:Microsoft.AspNetCore.Builder.RazorComponentsEndpointRouteBuilderExtensions.MapRazorComponents%2A>, supplying the `App` component as the root component type, and add a chained call to <xref:Microsoft.AspNetCore.Builder.ServerRazorComponentsEndpointConventionBuilderExtensions.AddInteractiveServerRenderMode%2A>:

```csharp
app.MapRazorComponents<App>()
Expand All @@ -281,15 +279,15 @@ Blazor Server apps are supported in .NET 8 without any code changes. Use the fol
- app.MapFallbackToPage("/_Host");
```

Add [Antiforgery Middleware](xref:blazor/security/index#antiforgery-support) to the request processing pipeline after the call to `app.UseRouting`. If there are calls to `app.UseRouting` and `app.UseEndpoints`, the call to `app.UseAntiforgery` must go between them. A call to `app.UseAntiforgery` must be placed after calls to `app.UseAuthentication` and `app.UseAuthorization`. There's no need to add antiforgery services (`builder.Services.AddAntiforgery()`), as they're added automatically by `AddRazorComponents`, which was covered earlier.
Add [Antiforgery Middleware](xref:blazor/security/index#antiforgery-support) to the request processing pipeline after the call to `app.UseRouting`. If there are calls to `app.UseRouting` and `app.UseEndpoints`, the call to `app.UseAntiforgery` must go between them. A call to `app.UseAntiforgery` must be placed after calls to `app.UseAuthentication` and `app.UseAuthorization`. There's no need to add antiforgery services (`builder.Services.AddAntiforgery()`), as they're added automatically by <xref:Microsoft.Extensions.DependencyInjection.RazorComponentsServiceCollectionExtensions.AddRazorComponents%2A>, which was covered earlier.

```csharp
app.UseAntiforgery();
```

1. If the Blazor Server app was configured to disable prerendering, you can continue to disable prerendering for the updated app. In the `App` component, change the value assigned to the `@rendermode` Razor directive attributes for the `HeadOutlet` and `Routes` components.
1. If the Blazor Server app was configured to disable prerendering, you can continue to disable prerendering for the updated app. In the `App` component, change the value assigned to the `@rendermode` Razor directive attributes for the <xref:Microsoft.AspNetCore.Components.Web.HeadOutlet> and `Routes` components.

Change the value of the `@rendermode` directive attribute for both the `HeadOutlet` and `Routes` components to disable prerendering:
Change the value of the `@rendermode` directive attribute for both the <xref:Microsoft.AspNetCore.Components.Web.HeadOutlet> and `Routes` components to disable prerendering:

```diff
- @rendermode="InteractiveServer"
Expand Down Expand Up @@ -351,13 +349,13 @@ Blazor WebAssembly apps are supported in .NET 8 without any code changes. Use th

1. Make the following changes to the `App.razor` file:

Replace the website's default website title (`<title>...</title>`) with a `HeadOutlet` component. Note the website title for use later and remove the title tags and title:
Replace the website's default website title (`<title>...</title>`) with a <xref:Microsoft.AspNetCore.Components.Web.HeadOutlet> component. Note the website title for use later and remove the title tags and title:

```diff
- <title>...</title>
```

Where you removed the title, place a `HeadOutlet` component assigning the Interactive WebAssembly render mode (prerendering disabled):
Where you removed the title, place a <xref:Microsoft.AspNetCore.Components.Web.HeadOutlet> component assigning the Interactive WebAssembly render mode (prerendering disabled):

```razor
<HeadOutlet @rendermode="new InteractiveWebAssemblyRenderMode(prerender: false)" />
Expand Down Expand Up @@ -396,14 +394,14 @@ Blazor WebAssembly apps are supported in .NET 8 without any code changes. Use th
+ <script src="_framework/blazor.web.js"></script>
```

1. Open the `.Client` project's layout file (`.Client/Shared/MainLayout.razor`) and add a `PageTitle` component with the website's default title (`{TITLE}` placeholder):
1. Open the `.Client` project's layout file (`.Client/Shared/MainLayout.razor`) and add a <xref:Microsoft.AspNetCore.Components.Web.PageTitle> component with the website's default title (`{TITLE}` placeholder):

```razor
<PageTitle>{TITLE}</PageTitle>
```

> [!NOTE]
> Other layout files should also receive a `PageTitle` component with the default website title.
> Other layout files should also receive a <xref:Microsoft.AspNetCore.Components.Web.PageTitle> component with the default website title.
>
> For more information, see <xref:blazor/components/control-head-content#set-a-page-title-for-components-via-a-layout>.

Expand All @@ -416,7 +414,7 @@ Blazor WebAssembly apps are supported in .NET 8 without any code changes. Use th

1. Update `.Server/Program.cs`:

Add Razor component and interactive WebAssembly component services to the project. Call `AddRazorComponents` with a chained call to `AddInteractiveWebAssemblyComponents`. Calling `AddRazorComponents` adds antiforgery services (`AddAntiforgery`) by default.
Add Razor component and interactive WebAssembly component services to the project. Call <xref:Microsoft.Extensions.DependencyInjection.RazorComponentsServiceCollectionExtensions.AddRazorComponents%2A> with a chained call to <xref:Microsoft.Extensions.DependencyInjection.WebAssemblyRazorComponentsBuilderExtensions.AddInteractiveWebAssemblyComponents%2A>. Calling <xref:Microsoft.Extensions.DependencyInjection.RazorComponentsServiceCollectionExtensions.AddRazorComponents%2A> adds antiforgery services (<xref:Microsoft.Extensions.DependencyInjection.AntiforgeryServiceCollectionExtensions.AddAntiforgery%2A>) by default.

```csharp
builder.Services.AddRazorComponents()
Expand All @@ -430,7 +428,7 @@ Blazor WebAssembly apps are supported in .NET 8 without any code changes. Use th
* After the call to `app.UseRouting`.
* If there are calls to `app.UseRouting` and `app.UseEndpoints`, the call to `app.UseAntiforgery` must go between them.
* The call to `app.UseAntiforgery` must be placed after a call to `app.UseAuthorization`, if present.
* There's no need to add antiforgery services (`builder.Services.AddAntiforgery()`), as they're added automatically by `AddRazorComponents`, which was covered earlier.
* There's no need to add antiforgery services (`builder.Services.AddAntiforgery()`), as they're added automatically by <xref:Microsoft.Extensions.DependencyInjection.RazorComponentsServiceCollectionExtensions.AddRazorComponents%2A>, which was covered earlier.

```csharp
app.UseAntiforgery();
Expand All @@ -448,7 +446,7 @@ Blazor WebAssembly apps are supported in .NET 8 without any code changes. Use th
- app.MapFallbackToFile("index.html");
```

Replace the preceding line with a call to `MapRazorComponents`, supplying the `App` component as the root component type, and add chained calls to `AddInteractiveWebAssemblyRenderMode` and `AddAdditionalAssemblies`:
Replace the preceding line with a call to <xref:Microsoft.AspNetCore.Builder.RazorComponentsEndpointRouteBuilderExtensions.MapRazorComponents%2A>, supplying the `App` component as the root component type, and add chained calls to <xref:Microsoft.AspNetCore.Builder.WebAssemblyRazorComponentsEndpointConventionBuilderExtensions.AddInteractiveWebAssemblyRenderMode%2A> and <xref:Microsoft.AspNetCore.Builder.RazorComponentsEndpointConventionBuilderExtensions.AddAdditionalAssemblies%2A>:

```csharp
app.MapRazorComponents<App>()
Expand Down Expand Up @@ -580,7 +578,7 @@ The `[Parameter]` attribute is no longer required when supplying a parameter fro

### Blazor Server script fallback policy authorization

In .NET 7, the Blazor Server script (`blazor.server.js`) is [served by Static Files Middleware](https://github.com/dotnet/aspnetcore/blob/v7.0.16/src/Components/Server/src/DependencyInjection/ConfigureStaticFilesOptions.cs). Placing the call for Static Files Middleware (`UseStaticFiles`) in the request processing pipeline before the call to Authorization Middleware (`UseAuthorization`) is sufficient in .NET 7 apps to serve the Blazor script to anonymous users.
In .NET 7, the Blazor Server script (`blazor.server.js`) is [served by Static Files Middleware](https://github.com/dotnet/aspnetcore/blob/v7.0.16/src/Components/Server/src/DependencyInjection/ConfigureStaticFilesOptions.cs). Placing the call for Static Files Middleware (<xref:Microsoft.AspNetCore.Builder.StaticFileExtensions.UseStaticFiles%2A>) in the request processing pipeline before the call to Authorization Middleware (<xref:Microsoft.AspNetCore.Builder.AuthorizationAppBuilderExtensions.UseAuthorization%2A>) is sufficient in .NET 7 apps to serve the Blazor script to anonymous users.

In .NET 8, the Blazor Server script is served [by its own endpoint](https://github.com/search?q=repo%3Adotnet%2Faspnetcore%20GetBlazorEndpoint&type=code), using endpoint routing. This change is introduced by [Fixed bug - Passing options to UseStaticFiles breaks Blazor Server (`dotnet/aspnetcore` #45897)](https://github.com/dotnet/aspnetcore/pull/45897).

Expand Down
Loading