Skip to content

Commit bb89d53

Browse files
authored
Mop up stray Blazor Preview 4 updates (#17910)
1 parent ac80e8f commit bb89d53

7 files changed

Lines changed: 22 additions & 10 deletions

File tree

aspnetcore/blazor/call-web-api.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to call a web API from a Blazor WebAssembly app using JSO
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 04/16/2020
8+
ms.date: 04/19/2020
99
no-loc: [Blazor, SignalR]
1010
uid: blazor/call-web-api
1111
---
@@ -112,7 +112,11 @@ JSON helper methods send requests to a URI (a web API in the following examples)
112112
}
113113
```
114114

115-
Calls to `PostAsJsonAsync` return an <xref:System.Net.Http.HttpResponseMessage>.
115+
Calls to `PostAsJsonAsync` return an <xref:System.Net.Http.HttpResponseMessage>. To deserialize the JSON content from the response message, use the `ReadFromJsonAsync<T>` extension method:
116+
117+
```csharp
118+
var content = response.content.ReadFromJsonAsync<WeatherForecast>();
119+
```
116120

117121
* `PutAsJsonAsync` &ndash; Sends an HTTP PUT request, including JSON-encoded content.
118122

@@ -141,7 +145,11 @@ JSON helper methods send requests to a URI (a web API in the following examples)
141145
}
142146
```
143147

144-
Calls to `PutAsJsonAsync` return an <xref:System.Net.Http.HttpResponseMessage>.
148+
Calls to `PutAsJsonAsync` return an <xref:System.Net.Http.HttpResponseMessage>. To deserialize the JSON content from the response message, use the `ReadFromJsonAsync<T>` extension method:
149+
150+
```csharp
151+
var content = response.content.ReadFromJsonAsync<WeatherForecast>();
152+
```
145153

146154
<xref:System.Net.Http> includes additional extension methods for sending HTTP requests and receiving HTTP responses. [HttpClient.DeleteAsync](xref:System.Net.Http.HttpClient.DeleteAsync*) is used to send an HTTP DELETE request to a web API.
147155

aspnetcore/includes/blazor-security/fetchdata-component.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ If the request failed because the token couldn't be provisioned without user int
3838
{
3939
httpClient.DefaultRequestHeaders.Add("Authorization",
4040
$"Bearer {token.Value}");
41-
forecasts = await httpClient.GetJsonAsync<WeatherForecast[]>(
41+
forecasts = await httpClient.GetFromJsonAsync<WeatherForecast[]>(
4242
"WeatherForecast");
4343
}
4444
else

aspnetcore/includes/blazor-security/imports-hosted.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@using System.Net.Http
2+
@using System.Net.Http.Json
23
@using Microsoft.AspNetCore.Components.Authorization
34
@using Microsoft.AspNetCore.Components.Forms
45
@using Microsoft.AspNetCore.Components.Routing

aspnetcore/includes/blazor-security/imports-standalone.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@using System.Net.Http
2+
@using System.Net.Http.Json
23
@using Microsoft.AspNetCore.Components.Authorization
34
@using Microsoft.AspNetCore.Components.Forms
45
@using Microsoft.AspNetCore.Components.Routing

aspnetcore/security/blazor/webassembly/additional-scenarios.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description:
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 03/30/2020
8+
ms.date: 04/19/2020
99
no-loc: [Blazor, SignalR]
1010
uid: security/blazor/webassembly/additional-scenarios
1111
---
@@ -134,7 +134,7 @@ The following example shows how to:
134134
{
135135
httpClient.DefaultRequestHeaders.Add("Authorization",
136136
$"Bearer {token.Value}");
137-
await httpClient.PostJsonAsync("Save", User);
137+
await httpClient.PostAsJsonAsync("Save", User);
138138
}
139139
else
140140
{

aspnetcore/security/blazor/webassembly/hosted-with-azure-active-directory.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ By [Javier Calvarro Nelson](https://github.com/javiercn) and [Luke Latham](https
1717

1818
[!INCLUDE[](~/includes/blazorwasm-3.2-template-article-notice.md)]
1919

20-
21-
2220
This article describes how to create a [Blazor WebAssembly hosted app](xref:blazor/hosting-models#blazor-webassembly) that uses [Azure Active Directory (AAD)](https://azure.microsoft.com/services/active-directory/) for authentication.
2321

2422
## Register apps in AAD B2C and create solution

aspnetcore/security/blazor/webassembly/index.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to secure Blazor WebAssemlby apps as Single Page Applicat
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 03/31/2020
8+
ms.date: 04/19/2020
99
no-loc: [Blazor, SignalR]
1010
uid: security/blazor/webassembly/index
1111
---
@@ -64,7 +64,11 @@ public class Program
6464
var builder = WebAssemblyHostBuilder.CreateDefault(args);
6565
builder.RootComponents.Add<App>("app");
6666

67-
services.AddBaseAddressHttpClient();
67+
builder.Services.AddSingleton(new HttpClient
68+
{
69+
BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)
70+
});
71+
6872
services.Add...;
6973

7074
ConfigureCommonServices(builder.Services);

0 commit comments

Comments
 (0)