Skip to content

Commit

Permalink
Merge branch 'main' into guardrex-patch-4
Browse files Browse the repository at this point in the history
  • Loading branch information
guardrex authored Dec 20, 2024
2 parents dfe523f + 261ab6a commit 3235a1a
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 14 deletions.
4 changes: 4 additions & 0 deletions aspnetcore/blazor/components/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,10 @@ For more information, see the following resources:
* <xref:mvc/views/tag-helpers/builtin-th/component-tag-helper>
* <xref:blazor/components/integration>

## `IHttpContextAccessor`/`HttpContext`

[!INCLUDE[](~/blazor/security/includes/httpcontext.md)]

<!--Reference links in article-->
[1]: <xref:mvc/views/razor#code>
[2]: <xref:mvc/views/razor#using>
Expand Down
6 changes: 3 additions & 3 deletions aspnetcore/blazor/fundamentals/signalr.md
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,7 @@ Use a <xref:Microsoft.AspNetCore.Components.Server.Circuits.CircuitHandler> to c

## Start the SignalR circuit at a different URL

Prevent automatically starting the app by adding `autostart="false"` to the Blazor `<script>` tag ([location of the Blazor start script](xref:blazor/project-structure#location-of-the-blazor-script)). Establish the circuit URL manually using `Blazor.start`. The following example uses the path `/signalr`:
Prevent automatically starting the app by adding `autostart="false"` to the Blazor `<script>` tag ([location of the Blazor start script](xref:blazor/project-structure#location-of-the-blazor-script)). Manually establish the circuit URL using `Blazor.start`. The following example uses the path `/signalr`:

```diff
- <script src="_framework/blazor.web.js"></script>
Expand All @@ -1470,15 +1470,15 @@ Prevent automatically starting the app by adding `autostart="false"` to the Blaz
+ </script>
```

Add the following <xref:Microsoft.AspNetCore.Builder.ComponentEndpointRouteBuilderExtensions.MapBlazorHub%2A> call with the `/signalr` path to the middleware processing pipeline in the server app's `Program` file:
Add the following <xref:Microsoft.AspNetCore.Builder.ComponentEndpointRouteBuilderExtensions.MapBlazorHub%2A> call with the hub path to the middleware processing pipeline in the server app's `Program` file:

```csharp
app.MapBlazorHub("/signalr");
```

:::moniker-end

## `IHttpContextAccessor`/`HttpContext` in Razor components
## `IHttpContextAccessor`/`HttpContext`

[!INCLUDE[](~/blazor/security/includes/httpcontext.md)]

Expand Down
10 changes: 2 additions & 8 deletions aspnetcore/blazor/security/blazor-web-app-with-oidc.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ The `BlazorWebAppOidc` project is the server-side project of the Blazor Web App.

The `BlazorWebAppOidc.http` file can be used for testing the weather data request. Note that the `BlazorWebAppOidc` project must be running to test the endpoint, and the endpoint is hardcoded into the file. For more information, see <xref:test/http-files>.

> [!NOTE]
> The server project uses <xref:Microsoft.AspNetCore.Http.IHttpContextAccessor>/<xref:Microsoft.AspNetCore.Http.HttpContext>, but never for interactively-rendered components. For more information, see <xref:blazor/security/interactive-server-side-rendering#ihttpcontextaccessorhttpcontext-in-razor-components>.
### Configuration

This section explains how to configure the sample app.
Expand Down Expand Up @@ -306,9 +303,6 @@ The `BlazorWebAppOidc` project is the server-side project of the Blazor Web App.

The `BlazorWebAppOidc.http` file can be used for testing the weather data request. Note that the `BlazorWebAppOidc` project must be running to test the endpoint, and the endpoint is hardcoded into the file. For more information, see <xref:test/http-files>.

> [!NOTE]
> The server project uses <xref:Microsoft.AspNetCore.Http.IHttpContextAccessor>/<xref:Microsoft.AspNetCore.Http.HttpContext>, but never for interactively-rendered components. For more information, see <xref:blazor/security/interactive-server-side-rendering#ihttpcontextaccessorhttpcontext-in-razor-components>.
### Configuration

This section explains how to configure the sample app.
Expand Down Expand Up @@ -503,7 +497,7 @@ Inspect the sample app for the following features:
* Automatic non-interactive token refresh with the help of a custom cookie refresher (`CookieOidcRefresher.cs`).
* The server project calls <xref:Microsoft.Extensions.DependencyInjection.WebAssemblyRazorComponentsBuilderExtensions.AddAuthenticationStateSerialization%2A> to add a server-side authentication state provider that uses <xref:Microsoft.AspNetCore.Components.PersistentComponentState> to flow the authentication state to the client. The client calls <xref:Microsoft.Extensions.DependencyInjection.WebAssemblyAuthenticationServiceCollectionExtensions.AddAuthenticationStateDeserialization%2A> to deserialize and use the authentication state passed by the server. The authentication state is fixed for the lifetime of the WebAssembly application.
* Requests to the Blazor Web App are proxied to the backend web API project (`MinimalApiJwt`). `MapForwarder` in the `Program` file adds direct forwarding of HTTP requests that match the specified pattern to a specific destination using default configuration for the outgoing request, customized transforms, and default HTTP client:
* When rendering the `Weather` component on the server, the component uses the `ServerWeatherForecaster` to proxy the request for weather data with the user's access token.
* When rendering the `Weather` component on the server, the component uses the `ServerWeatherForecaster` class to proxy the request for weather data with the user's access token. <xref:Microsoft.AspNetCore.Http.IHttpContextAccessor.HttpContext?displayProperty=nameWithType> determines if an <xref:Microsoft.AspNetCore.Http.HttpContext> is available for use by the `GetWeatherForecastAsync` method. For more information, see <xref:blazor/components/index#ihttpcontextaccessorhttpcontext>.
* When the component is rendered on the client, the component uses the `ClientWeatherForecaster` service implementation, which uses a preconfigured <xref:System.Net.Http.HttpClient> (in the client project's `Program` file) to make a web API call to the server project. A Minimal API endpoint (`/weather-forecast`) defined in the server project's `Program` file transforms the request with the user's access token to obtain the weather data.

:::moniker-end
Expand All @@ -513,7 +507,7 @@ Inspect the sample app for the following features:
* Automatic non-interactive token refresh with the help of a custom cookie refresher (`CookieOidcRefresher.cs`).
* The `PersistingAuthenticationStateProvider` class (`PersistingAuthenticationStateProvider.cs`) is a server-side <xref:Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider> that uses <xref:Microsoft.AspNetCore.Components.PersistentComponentState> to flow the authentication state to the client, which is then fixed for the lifetime of the WebAssembly application.
* Requests to the Blazor Web App are proxied to the backend web API project (`MinimalApiJwt`). `MapForwarder` in the `Program` file adds direct forwarding of HTTP requests that match the specified pattern to a specific destination using default configuration for the outgoing request, customized transforms, and default HTTP client:
* When rendering the `Weather` component on the server, the component uses the `ServerWeatherForecaster` to proxy the request for weather data with the user's access token.
* When rendering the `Weather` component on the server, the component uses the `ServerWeatherForecaster` class to proxy the request for weather data with the user's access token. <xref:Microsoft.AspNetCore.Http.IHttpContextAccessor.HttpContext?displayProperty=nameWithType> determines if an <xref:Microsoft.AspNetCore.Http.HttpContext> is available for use by the `GetWeatherForecastAsync` method. For more information, see <xref:blazor/components/index#ihttpcontextaccessorhttpcontext>.
* When the component is rendered on the client, the component uses the `ClientWeatherForecaster` service implementation, which uses a preconfigured <xref:System.Net.Http.HttpClient> (in the client project's `Program` file) to make a web API call to the server project. A Minimal API endpoint (`/weather-forecast`) defined in the server project's `Program` file transforms the request with the user's access token to obtain the weather data.

:::moniker-end
Expand Down
2 changes: 1 addition & 1 deletion aspnetcore/blazor/security/includes/httpcontext.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:::moniker range=">= aspnetcore-8.0"

<xref:Microsoft.AspNetCore.Http.IHttpContextAccessor> must be avoided with interactive rendering because there isn't a valid `HttpContext` available.
<xref:Microsoft.AspNetCore.Http.IHttpContextAccessor> generally should be avoided with interactive rendering because a valid <xref:Microsoft.AspNetCore.Http.HttpContext> isn't always available.

<xref:Microsoft.AspNetCore.Http.IHttpContextAccessor> can be used for components that are statically rendered on the server. **However, we recommend avoiding it if possible.**

Expand Down
2 changes: 1 addition & 1 deletion aspnetcore/blazor/security/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ The built-in or custom <xref:Microsoft.AspNetCore.Components.Authorization.Authe

For more information on server-side authentication, see <xref:blazor/security/index>.

### `IHttpContextAccessor`/`HttpContext` in Razor components
### `IHttpContextAccessor`/`HttpContext`

[!INCLUDE[](~/blazor/security/includes/httpcontext.md)]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ In general, we recommend that you avoid rendering components that contain sensit

[!INCLUDE[](~/blazor/security/includes/shared-state.md)]

## `IHttpContextAccessor`/`HttpContext` in Razor components
## `IHttpContextAccessor`/`HttpContext`

[!INCLUDE[](~/blazor/security/includes/httpcontext.md)]

Expand Down

0 comments on commit 3235a1a

Please sign in to comment.