You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -5,7 +5,7 @@ description: Learn how to call a web API from Blazor apps.
5
5
monikerRange: '>= aspnetcore-3.1'
6
6
ms.author: wpickett
7
7
ms.custom: mvc
8
-
ms.date: 05/30/2025
8
+
ms.date: 06/03/2025
9
9
uid: blazor/call-web-api
10
10
---
11
11
# Call a web API from ASP.NET Core Blazor
@@ -124,6 +124,10 @@ To configure a production distributed cache provider, see <xref:performance/cach
124
124
125
125
Formoreinformation, see [Tokencacheserialization: Distributedcaches](/entra/msal/dotnet/how-to/token-cache-serialization?tabs=msal#distributed-caches). However, thecodeexamplesshowndon't apply to ASP.NET Core apps, which configure distributed caches via <xref:Microsoft.Extensions.DependencyInjection.MemoryCacheServiceCollectionExtensions.AddDistributedMemoryCache%2A>, not <xref:Microsoft.Identity.Web.TokenCacheExtensions.AddDistributedTokenCache%2A>.
changes when updating this portion of content. -->
130
+
127
131
UseasharedDataProtectionkeyringinproductionsothatinstancesoftheappacrossserversinawebfarmcandecrypttokens when <xref:Microsoft.Identity.Web.TokenCacheProviders.Distributed.MsalDistributedTokenCacheAdapterOptions.Encrypt%2A?displayProperty=nameWithType> is set to `true`.
128
132
129
133
> [!NOTE]
@@ -135,22 +139,73 @@ Use a shared Data Protection key ring in production so that instances of the app
*Uploadthekeyfile (`keys.xml`) tothecontainerofthestorageaccount. Usethecontextmenu's **View/edit** command at the end of the key row in the portal to confirm that the blob contains the preceding content.
171
+
172
+
*Usethecontextmenu's **Generate SAS** command to obtain the blob'sURIwithasharedaccesssignature (SAS). WhenyoucreatetheSAS, usethefollowingpermissions: `Read`, `Add`, `Create`, `Write`, `Delete`. TheURIisusedlaterwherethe `{BLOBURIWITHSAS}` placeholderappears.
*Whenkeyencryptionisactive, keysinthekeyfileincludethecomment, ":::no-loc text="ThiskeyisencryptedwithAzureKeyVault.":::" After starting the app, select the **View/edit** command from the context menu at the end of the key row to confirm that a key is present with key vault security applied.
`{BLOBURIWITHSAS}`:ThefullURIwherethekeyfileshouldbestoredwiththeSAStokenasaquerystringparameter. TheURIisgeneratedbyAzureStorage when you request a SAS for the uploaded key file. The container name in the following example is `data-protection`, and the storage account name is `contoso`. The key file is named `keys.xml`.
203
+
204
+
Example::::no-loctext="https://contoso.blob.core.windows.net/data-protection/keys.xml?sp={PERMISSIONS}&st={START DATETIME}&se={EXPIRATION DATETIME}&spr=https&sv={STORAGE VERSION DATE}&sr=c&sig={TOKEN}":::
@@ -304,6 +364,27 @@ The solution includes a demonstration of obtaining weather data securely via an
304
364
305
365
:::moniker-end
306
366
367
+
## Disposal of `HttpRequestMessage`, `HttpResponseMessage`, and `HttpClient`
368
+
369
+
An<xref:System.Net.Http.HttpRequestMessage>withoutabodydoesn't require explicit disposal with a [`using` declaration (C# 8 or later)](/dotnet/csharp/language-reference/proposals/csharp-8.0/using) or a `using` block (earlier than C# 8), but we recommend disposing with every use for the following reasons:
***Never***disposeof<xref:System.Net.Http.HttpClient>instancescreatedbycalling<xref:System.Net.Http.IHttpClientFactory.CreateClient%2A>becausethey're managed by the framework.
@@ -737,7 +818,7 @@ As of C# 11 (.NET 7), you can compose a JSON string as a [raw string literal](/d
737
818
<xref:System.Net.Http.Json.HttpClientJsonExtensions.PatchAsJsonAsync%2A>returnsan <xref:System.Net.Http.HttpResponseMessage>. TodeserializetheJSONcontentfromtheresponsemessage, usethe<xref:System.Net.Http.Json.HttpContentJsonExtensions.ReadFromJsonAsync%2A>extensionmethod. ThefollowingexamplereadsJSONtodoitemdataasanarray. Anemptyarrayiscreatedifnoitemdataisreturnedbythemethod, so `content` isn't null after the statement executes:
0 commit comments