Skip to content

Commit 522ad36

Browse files
authored
Merge pull request #35315 from dotnet/main
2 parents 3216eeb + 776622e commit 522ad36

File tree

7 files changed

+884
-598
lines changed

7 files changed

+884
-598
lines changed

aspnetcore/blazor/call-web-api.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to call a web API from Blazor apps.
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 11/12/2024
8+
ms.date: 04/29/2025
99
uid: blazor/call-web-api
1010
---
1111
# Call a web API from ASP.NET Core Blazor
@@ -37,7 +37,8 @@ For client-side rendering (CSR), which includes Interactive WebAssembly componen
3737
builder.Services.AddScoped(sp =>
3838
new HttpClient
3939
{
40-
BaseAddress = new Uri(builder.Configuration["FrontendUrl"] ?? "https://localhost:5002")
40+
BaseAddress = new Uri(builder.Configuration["FrontendUrl"] ??
41+
"https://localhost:5002")
4142
});
4243
```
4344

@@ -108,7 +109,11 @@ The solution demonstrates calling a secure web API for the following:
108109

109110
### `BlazorWebAppOidc`
110111

111-
A Blazor Web App with global Auto interactivity that uses OIDC authentication with Microsoft Entra without using Entra-specific packages. The solution includes a demonstration of obtaining weather data securely via a web API when a component that adopts Interactive Auto rendering is rendered on the client.
112+
A Blazor Web App with global Auto interactivity that uses OIDC authentication with Microsoft Entra without using Entra-specific packages. The sample demonstrates how to [use a token handler for web API calls](xref:blazor/security/additional-scenarios#use-a-token-handler-for-web-api-calls) to call an external secure web API.
113+
114+
### `BlazorWebAppOidcServer`
115+
116+
A Blazor Web App with global Interactive Server interactivity that uses OIDC authentication with Microsoft Entra without using Entra-specific packages. The sample demonstrates how to [pass an access token](xref:blazor/security/additional-scenarios#use-a-token-handler-for-web-api-calls) to call an external secure web API.
112117

113118
### `BlazorWebAppOidcBff`
114119

@@ -117,15 +122,15 @@ A Blazor Web App with global Auto interactivity that uses:
117122
* OIDC authentication with Microsoft Entra without using Entra-specific packages.
118123
* The [Backend for Frontend (BFF) pattern](/azure/architecture/patterns/backends-for-frontends), which is a pattern of app development that creates backend services for frontend apps or interfaces.
119124

120-
The solution includes a demonstration of obtaining weather data securely via a web API when a component that adopts Interactive Auto rendering is rendered on the client.
125+
The solution includes a demonstration of obtaining weather data securely via an external web API when a component that adopts Interactive Auto rendering is rendered on the client.
121126

122127
:::moniker-end
123128

124129
:::moniker range=">= aspnetcore-9.0"
125130

126131
### `BlazorWebAppEntra`
127132

128-
A Blazor Web App with global Auto interactivity that uses [Microsoft identity platform](/entra/identity-platform/)/[Microsoft Identity Web packages](/entra/msal/dotnet/microsoft-identity-web/) for [Microsoft Entra ID](https://www.microsoft.com/security/business/microsoft-entra). The solution includes a demonstration of obtaining weather data securely via a web API when a component that adopts Interactive Auto rendering is rendered on the client.
133+
A Blazor Web App with global Auto interactivity that uses [Microsoft identity platform](/entra/identity-platform/)/[Microsoft Identity Web packages](/entra/msal/dotnet/microsoft-identity-web/) for [Microsoft Entra ID](https://www.microsoft.com/security/business/microsoft-entra). The solution includes a demonstration of obtaining weather data securely via an external web API when a component that adopts Interactive Auto rendering is rendered on the client.
129134

130135
### `BlazorWebAppEntraBff`
131136

@@ -134,7 +139,7 @@ A Blazor Web App with global Auto interactivity that uses:
134139
* [Microsoft identity platform](/entra/identity-platform/)/[Microsoft Identity Web packages](/entra/msal/dotnet/microsoft-identity-web/) for [Microsoft Entra ID](https://www.microsoft.com/security/business/microsoft-entra).
135140
* The [Backend for Frontend (BFF) pattern](/azure/architecture/patterns/backends-for-frontends), which is a pattern of app development that creates backend services for frontend apps or interfaces.
136141

137-
The solution includes a demonstration of obtaining weather data securely via a web API when a component that adopts Interactive Auto rendering is rendered on the client.
142+
The solution includes a demonstration of obtaining weather data securely via an external web API when a component that adopts Interactive Auto rendering is rendered on the client.
138143

139144
:::moniker-end
140145

aspnetcore/blazor/components/httpcontext.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn about IHttpContextAccessor and HttpContext in ASP.NET Core Bl
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 01/30/2025
8+
ms.date: 04/29/2025
99
uid: blazor/components/httpcontext
1010
---
1111
# `IHttpContextAccessor`/`HttpContext` in ASP.NET Core Blazor apps
@@ -16,23 +16,21 @@ uid: blazor/components/httpcontext
1616

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

19-
<xref:Microsoft.AspNetCore.Http.IHttpContextAccessor> can be used for components that are statically rendered on the server. **However, we recommend avoiding it if possible.**
19+
<xref:Microsoft.AspNetCore.Http.IHttpContextAccessor> can be used during static server-side rendering (static SSR), for example in statically-rendered root components, and when [using a token handler for web API calls](xref:blazor/security/additional-scenarios#use-a-token-handler-for-web-api-calls) on the server. **We recommend avoiding <xref:Microsoft.AspNetCore.Http.IHttpContextAccessor> when static SSR or code running on the server can't be guaranteed.**
2020

21-
<xref:Microsoft.AspNetCore.Http.HttpContext> can be used as a [cascading parameter](xref:Microsoft.AspNetCore.Components.CascadingParameterAttribute) only in *statically-rendered root components* for general tasks, such as inspecting and modifying headers or other properties in the `App` component (`Components/App.razor`). The value is always `null` for interactive rendering.
21+
<xref:Microsoft.AspNetCore.Http.HttpContext> can be used as a [cascading parameter](xref:Microsoft.AspNetCore.Components.CascadingParameterAttribute) only in statically-rendered root components or during static SSR for general tasks, such as inspecting and modifying headers or other properties in the `App` component (`App.razor`). The value is `null` during interactive rendering.
2222

2323
```csharp
2424
[CascadingParameter]
2525
public HttpContext? HttpContext { get; set; }
2626
```
2727

28-
During interactive rendering, an <xref:Microsoft.AspNetCore.Http.HttpContext> instance might not even exist. For scenarios where the <xref:Microsoft.AspNetCore.Http.HttpContext> is required in interactive components, we recommend flowing context data with [persistent component state](xref:blazor/components/prerender#persist-prerendered-state) from the server.
29-
3028
For additional context in *advanced* edge cases&dagger;, see the discussion in the following articles:
3129

3230
* [HttpContext is valid in Interactive Server Rendering Blazor page (`dotnet/AspNetCore.Docs` #34301)](https://github.com/dotnet/AspNetCore.Docs/issues/34301)
3331
* [Security implications of using IHttpContextAccessor in Blazor Server (`dotnet/aspnetcore` #45699)](https://github.com/dotnet/aspnetcore/issues/45699)
3432

35-
&dagger;Most developers building and maintaining Blazor apps don't need to delve into advanced concepts as long as the general guidance in this article is followed.
33+
&dagger;Most developers building and maintaining Blazor apps don't need to delve into advanced concepts when the general guidance in this article is followed. The most important concept to keep in mind is that <xref:Microsoft.AspNetCore.Http.HttpContext> is fundamentally a server-based, request-response feature that's only generally available on the server during static SSR and only created when a user's circuit is established.
3634

3735
:::moniker-end
3836

aspnetcore/blazor/fundamentals/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ Samples apps in the repository:
188188
* Blazor Web App Movies tutorial sample (<xref:blazor/tutorials/movie-database-app/index>)
189189
* Blazor Web App with SignalR (<xref:blazor/tutorials/signalr-blazor>)
190190
* Two Blazor Web Apps and a Blazor WebAssembly app for calling web (server) APIs (<xref:blazor/call-web-api>)
191-
* Blazor Web App with OIDC (BFF and non-BFF patterns) (<xref:blazor/security/blazor-web-app-oidc>)
191+
* Blazor Web App with OIDC (<xref:blazor/security/blazor-web-app-oidc>)
192192
* Blazor Web App with Entra (<xref:blazor/security/blazor-web-app-entra>)
193193
* Blazor WebAssembly scopes-enabled logging (<xref:blazor/fundamentals/logging#client-side-log-scopes>)
194194
* Blazor WebAssembly with ASP.NET Core Identity (<xref:blazor/security/webassembly/standalone-with-identity/index>)

0 commit comments

Comments
 (0)