Skip to content

Commit 701a5ca

Browse files
committed
IHttpContextAccessor and HttpContext updates
1 parent 5c792fc commit 701a5ca

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

aspnetcore/blazor/components/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,6 +1854,10 @@ For more information, see the following resources:
18541854
* <xref:mvc/views/tag-helpers/builtin-th/component-tag-helper>
18551855
* <xref:blazor/components/integration>
18561856

1857+
## `IHttpContextAccessor`/`HttpContext`
1858+
1859+
[!INCLUDE[](~/blazor/security/includes/httpcontext.md)]
1860+
18571861
<!--Reference links in article-->
18581862
[1]: <xref:mvc/views/razor#code>
18591863
[2]: <xref:mvc/views/razor#using>

aspnetcore/blazor/fundamentals/signalr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ Use a <xref:Microsoft.AspNetCore.Components.Server.Circuits.CircuitHandler> to c
14521452

14531453
:::moniker-end
14541454

1455-
## `IHttpContextAccessor`/`HttpContext` in Razor components
1455+
## `IHttpContextAccessor`/`HttpContext`
14561456

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

aspnetcore/blazor/security/blazor-web-app-with-oidc.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ The `BlazorWebAppOidc` project is the server-side project of the Blazor Web App.
4545
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>.
4646

4747
> [!NOTE]
48-
> 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>.
48+
> 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>.
4949
5050
### Configuration
5151

@@ -306,9 +306,6 @@ The `BlazorWebAppOidc` project is the server-side project of the Blazor Web App.
306306

307307
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>.
308308

309-
> [!NOTE]
310-
> 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>.
311-
312309
### Configuration
313310

314311
This section explains how to configure the sample app.
@@ -503,7 +500,7 @@ Inspect the sample app for the following features:
503500
* Automatic non-interactive token refresh with the help of a custom cookie refresher (`CookieOidcRefresher.cs`).
504501
* 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.
505502
* 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:
506-
* 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.
503+
* 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. In the `ServerWeatherForecaster` class, <xref:Microsoft.AspNetCore.Http.IHttpContextAccessor> is checked to determine if a valid <xref:Microsoft.AspNetCore.Http.HttpContext> is available. <xref:Microsoft.AspNetCore.Http.HttpContext> is only used by the `GetWeatherForecastAsync` method if it's available. For more information, see <xref:blazor/components/index#ihttpcontextaccessorhttpcontext>.
507504
* 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.
508505

509506
:::moniker-end
@@ -513,7 +510,7 @@ Inspect the sample app for the following features:
513510
* Automatic non-interactive token refresh with the help of a custom cookie refresher (`CookieOidcRefresher.cs`).
514511
* 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.
515512
* 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:
516-
* 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.
513+
* 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. In the `ServerWeatherForecaster` class, <xref:Microsoft.AspNetCore.Http.IHttpContextAccessor> is checked to determine if a valid <xref:Microsoft.AspNetCore.Http.HttpContext> is available. <xref:Microsoft.AspNetCore.Http.HttpContext> is only used by the `GetWeatherForecastAsync` method if it's available. For more information, see <xref:blazor/components/index#ihttpcontextaccessorhttpcontext>.
517514
* 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.
518515

519516
:::moniker-end

aspnetcore/blazor/security/includes/httpcontext.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
:::moniker range=">= aspnetcore-8.0"
22

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

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

aspnetcore/blazor/security/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ The built-in or custom <xref:Microsoft.AspNetCore.Components.Authorization.Authe
108108

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

111-
### `IHttpContextAccessor`/`HttpContext` in Razor components
111+
### `IHttpContextAccessor`/`HttpContext`
112112

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

aspnetcore/blazor/security/interactive-server-side-rendering.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ In general, we recommend that you avoid rendering components that contain sensit
6060

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

63-
## `IHttpContextAccessor`/`HttpContext` in Razor components
63+
## `IHttpContextAccessor`/`HttpContext`
6464

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

0 commit comments

Comments
 (0)