Skip to content

Commit 7bb14d0

Browse files
authored
Merge pull request #17982 from dotnet/master
2 parents 73b65f6 + 682fc99 commit 7bb14d0

20 files changed

Lines changed: 490 additions & 45 deletions

aspnetcore/blazor/call-web-api.md

Lines changed: 16 additions & 1 deletion
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/19/2020
8+
ms.date: 04/23/2020
99
no-loc: [Blazor, SignalR]
1010
uid: blazor/call-web-api
1111
---
@@ -216,6 +216,19 @@ When running on WebAssembly in a Blazor WebAssembly app, use [HttpClient](xref:f
216216
}
217217
```
218218

219+
HTTP fetch request options can be configured with `HttpRequestMessage` extension methods shown in the following table.
220+
221+
| `HttpRequestMessage` extension method | Fetch request property |
222+
| ------------------------------------- | ---------------------- |
223+
| `SetBrowserRequestCredentials` | [credentials](https://developer.mozilla.org/docs/Web/API/Request/credentials) |
224+
| `SetBrowserRequestCache` | [cache](https://developer.mozilla.org/docs/Web/API/Request/cache) |
225+
| `SetBrowserRequestMode` | [mode](https://developer.mozilla.org/docs/Web/API/Request/mode) |
226+
| `SetBrowserRequestIntegrity` | [integrity](https://developer.mozilla.org/docs/Web/API/Request/integrity) |
227+
228+
You can set additional options using the more generic `SetBrowserRequestOption` extension method.
229+
230+
The HTTP response is typically buffered in a Blazor WebAssembly app to enable support for sync reads on the response content. To enable support for response streaming, use the `SetBrowserResponseStreamingEnabled` extension method on the request.
231+
219232
For more information on Fetch API options, see [MDN web docs: WindowOrWorkerGlobalScope.fetch():Parameters](https://developer.mozilla.org/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters).
220233

221234
When sending credentials (authorization cookies/headers) on CORS requests, the `Authorization` header must be allowed by the CORS policy.
@@ -239,6 +252,8 @@ For more information, see <xref:security/cors> and the sample app's HTTP Request
239252

240253
## Additional resources
241254

255+
* [Request additional access tokens](xref:security/blazor/webassembly/additional-scenarios#request-additional-access-tokens)
256+
* [Attach tokens to outgoing requests](xref:security/blazor/webassembly/additional-scenarios#attach-tokens-to-outgoing-requests)
242257
* <xref:fundamentals/http-requests>
243258
* <xref:security/enforcing-ssl>
244259
* [Kestrel HTTPS endpoint configuration](xref:fundamentals/servers/kestrel#endpoint-configuration)

aspnetcore/blazor/common/samples/3.x/BlazorWebAssemblySample/BlazorSample.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0-preview4.20210.8" />
10-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0-preview4.20210.8" PrivateAssets="all" />
11-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0-preview4.20210.8" PrivateAssets="all" />
9+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0-preview5.20216.8" />
10+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0-preview5.20216.8" PrivateAssets="all" />
11+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0-preview5.20216.8" PrivateAssets="all" />
1212
<PackageReference Include="System.Net.Http.Json" Version="3.2.0-preview5.20210.3" />
1313
</ItemGroup>
1414

aspnetcore/blazor/get-started.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ To get started with Blazor, follow the guidance for your choice of tooling:
2828
1. Install the [Blazor WebAssembly](xref:blazor/hosting-models#blazor-webassembly) preview template by running the following command:
2929

3030
```dotnetcli
31-
dotnet new -i Microsoft.AspNetCore.Components.WebAssembly.Templates::3.2.0-preview4.20210.8
31+
dotnet new -i Microsoft.AspNetCore.Components.WebAssembly.Templates::3.2.0-preview5.20216.8
3232
```
3333

3434
1. Create a new project.
@@ -48,7 +48,7 @@ To get started with Blazor, follow the guidance for your choice of tooling:
4848
1. Optionally install the [Blazor WebAssembly](xref:blazor/hosting-models#blazor-webassembly) preview template by running the following command:
4949

5050
```dotnetcli
51-
dotnet new -i Microsoft.AspNetCore.Components.WebAssembly.Templates::3.2.0-preview4.20210.8
51+
dotnet new -i Microsoft.AspNetCore.Components.WebAssembly.Templates::3.2.0-preview5.20216.8
5252
```
5353

5454
> [!NOTE]
@@ -111,7 +111,7 @@ If a prompt appears to trust the development certificate, trust the certificate
111111
1. Optionally install the [Blazor WebAssembly](xref:blazor/hosting-models#blazor-webassembly) preview template by running the following command:
112112

113113
```dotnetcli
114-
dotnet new -i Microsoft.AspNetCore.Components.WebAssembly.Templates::3.2.0-preview4.20210.8
114+
dotnet new -i Microsoft.AspNetCore.Components.WebAssembly.Templates::3.2.0-preview5.20216.8
115115
```
116116

117117
> [!NOTE]

aspnetcore/blazor/handle-errors.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Discover how ASP.NET Core Blazor how Blazor manages unhandled excep
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 03/29/2020
8+
ms.date: 04/23/2020
99
no-loc: [Blazor, SignalR]
1010
uid: blazor/handle-errors
1111
---
@@ -106,6 +106,8 @@ During development, Blazor usually sends the full details of exceptions to the b
106106

107107
You must decide which incidents to log and the level of severity of logged incidents. Hostile users might be able to trigger errors deliberately. For example, don't log an incident from an error where an unknown `ProductId` is supplied in the URL of a component that displays product details. Not all errors should be treated as high-severity incidents for logging.
108108

109+
For more information, see <xref:fundamentals/logging/index#create-logs-in-blazor>.
110+
109111
## Places where errors may occur
110112

111113
Framework and app code may trigger unhandled exceptions in any of the following locations:

aspnetcore/blazor/hosting-model-configuration.md

Lines changed: 127 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ description: Learn about Blazor hosting model configuration, including how to in
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 04/16/2020
8+
ms.date: 04/23/2020
99
no-loc: [Blazor, SignalR]
1010
uid: blazor/hosting-model-configuration
1111
---
1212
# ASP.NET Core Blazor hosting model configuration
1313

14-
By [Daniel Roth](https://github.com/danroth27)
14+
By [Daniel Roth](https://github.com/danroth27) and [Luke Latham](https://github.com/guardrex)
1515

1616
[!INCLUDE[](~/includes/blazorwasm-preview-notice.md)]
1717

@@ -92,12 +92,21 @@ The `IWebAssemblyHostEnvironment.BaseAddress` property can be used during startu
9292

9393
### Configuration
9494

95-
As of the ASP.NET Core 3.2 Preview 3 release ([current release is 3.2 Preview 4](xref:blazor/get-started)), Blazor WebAssembly supports configuration from:
95+
Blazor WebAssembly supports configuration from:
9696

97-
* *wwwroot/appsettings.json*
98-
* *wwwroot/appsettings.{ENVIRONMENT}.json*
97+
* The [File Configuration Provider](xref:fundamentals/configuration/index#file-configuration-provider) for app settings files by default:
98+
* *wwwroot/appsettings.json*
99+
* *wwwroot/appsettings.{ENVIRONMENT}.json*
100+
* Other [configuration providers](xref:fundamentals/configuration/index) registered by the app.
99101

100-
Add an *appsettings.json* file in the *wwwroot* folder:
102+
> [!WARNING]
103+
> Configuration in a Blazor WebAssembly app is visible to users. **Don't store app secrets or credentials in configuration.**
104+
105+
For more information on configuration providers, see <xref:fundamentals/configuration/index>.
106+
107+
#### App settings configuration
108+
109+
*wwwroot/appsettings.json*:
101110

102111
```json
103112
{
@@ -117,8 +126,113 @@ Inject an <xref:Microsoft.Extensions.Configuration.IConfiguration> instance into
117126
<p>Message: @Configuration["message"]</p>
118127
```
119128

120-
> [!WARNING]
121-
> Configuration in a Blazor WebAssembly app is visible to users. **Don't store app secrets or credentials in configuration.**
129+
#### Provider configuration
130+
131+
The following example uses a <xref:Microsoft.Extensions.Configuration.Memory.MemoryConfigurationSource> and the [File Configuration Provider](xref:fundamentals/configuration/index#file-configuration-provider) to supply additional configuration:
132+
133+
`Program.Main`:
134+
135+
```csharp
136+
using Microsoft.Extensions.Configuration;
137+
138+
...
139+
140+
var vehicleData = new Dictionary<string, string>()
141+
{
142+
{ "color", "blue" },
143+
{ "type", "car" },
144+
{ "wheels:count", "3" },
145+
{ "wheels:brand", "Blazin" },
146+
{ "wheels:brand:type", "rally" },
147+
{ "wheels:year", "2008" },
148+
};
149+
150+
var memoryConfig = new MemoryConfigurationSource { InitialData = vehicleData };
151+
152+
...
153+
154+
builder.Configuration
155+
.Add(memoryConfig)
156+
.AddJsonFile("cars.json", optional: false, reloadOnChange: true);
157+
```
158+
159+
Inject an <xref:Microsoft.Extensions.Configuration.IConfiguration> instance into a component to access the configuration data:
160+
161+
```razor
162+
@page "/"
163+
@using Microsoft.Extensions.Configuration
164+
@inject IConfiguration Configuration
165+
166+
<h1>Configuration example</h1>
167+
168+
<h2>Wheels</h2>
169+
170+
<ul>
171+
<li>Count: @Configuration["wheels:count"]</p>
172+
<li>Brand: @Configuration["wheels:brand"]</p>
173+
<li>Type: @Configuration["wheels:brand:type"]</p>
174+
<li>Year: @Configuration["wheels:year"]</p>
175+
</ul>
176+
177+
@code {
178+
var wheelsSection = Configuration.GetSection("wheels");
179+
180+
...
181+
}
182+
```
183+
184+
#### Authentication configuration
185+
186+
*wwwroot/appsettings.json*:
187+
188+
```json
189+
{
190+
"AzureAD": {
191+
"Authority": "https://login.microsoftonline.com/",
192+
"ClientId": "aeaebf0f-d416-4d92-a08f-e1d5b51fc494"
193+
}
194+
}
195+
```
196+
197+
`Program.Main`:
198+
199+
```csharp
200+
builder.Services.AddOidcAuthentication(options =>
201+
builder.Configuration.Bind("AzureAD", options);
202+
```
203+
204+
#### Logging configuration
205+
206+
*wwwroot/appsettings.json*:
207+
208+
```json
209+
{
210+
"Logging": {
211+
"LogLevel": {
212+
"Default": "Information",
213+
"Microsoft": "Warning",
214+
"Microsoft.Hosting.Lifetime": "Information"
215+
}
216+
}
217+
}
218+
```
219+
220+
`Program.Main`:
221+
222+
```csharp
223+
builder.Logging.AddConfiguration(
224+
builder.Configuration.GetSection("Logging"));
225+
```
226+
227+
#### Host builder configuration
228+
229+
`Program.Main`:
230+
231+
```csharp
232+
var hostname = builder.Configuration["HostName"];
233+
```
234+
235+
#### Cached configuration
122236

123237
Configuration files are cached for offline use. With [Progressive Web Applications (PWAs)](xref:blazor/progressive-web-app), you can only update configuration files when creating a new deployment. Editing configuration files between deployments has no effect because:
124238

@@ -129,7 +243,7 @@ For more information on how background updates are handled by PWAs, see <xref:bl
129243

130244
### Logging
131245

132-
For information on Blazor WebAssembly logging support, see <xref:fundamentals/logging/index#create-logs-in-blazor-webassembly>.
246+
For information on Blazor WebAssembly logging support, see <xref:fundamentals/logging/index#create-logs-in-blazor>.
133247

134248
## Blazor Server
135249

@@ -247,3 +361,7 @@ To configure the SignalR client in the *Pages/_Host.cshtml* file:
247361
});
248362
</script>
249363
```
364+
365+
### Logging
366+
367+
For information on Blazor Server logging support, see <xref:fundamentals/logging/index#create-logs-in-blazor>.

aspnetcore/fundamentals/logging/index.md

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to use the logging framework provided by the Microsoft.Ex
55
monikerRange: '>= aspnetcore-2.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 4/17/2020
8+
ms.date: 4/23/2020
99
uid: fundamentals/logging/index
1010
---
1111
# Logging in .NET Core and ASP.NET Core
@@ -159,7 +159,9 @@ If you need to configure a service that depends on `ILogger<T>`, you can still d
159159

160160
The preceding highlighted code is a `Func` that runs the first time the DI container needs to construct an instance of `MyService`. You can access any of the registered services in this way.
161161

162-
### Create logs in Blazor WebAssembly
162+
### Create logs in Blazor
163+
164+
#### Blazor WebAssembly
163165

164166
Configure logging in Blazor WebAssembly apps with the `WebAssemblyHostBuilder.Logging` property in `Program.Main`:
165167

@@ -176,6 +178,63 @@ builder.Logging.AddProvider(new CustomLoggingProvider());
176178

177179
The `Logging` property is of type <xref:Microsoft.Extensions.Logging.ILoggingBuilder>, so all of the extension methods available on <xref:Microsoft.Extensions.Logging.ILoggingBuilder> are also available on `Logging`.
178180

181+
#### Log in Razor components
182+
183+
Loggers respect app startup configuration.
184+
185+
The `using` directive for <xref:Microsoft.Extensions.Logging> is required to support Intellisense completions for APIs, such as <xref:Microsoft.Extensions.Logging.LoggerExtensions.LogWarning%2A> and <xref:Microsoft.Extensions.Logging.LoggerExtensions.LogError%2A>.
186+
187+
The following example demonstrates logging with an <xref:Microsoft.Extensions.Logging.ILogger> in Razor components:
188+
189+
```razor
190+
@page "/counter"
191+
@using Microsoft.Extensions.Logging;
192+
@inject ILogger<Counter> logger;
193+
194+
<h1>Counter</h1>
195+
196+
<p>Current count: @currentCount</p>
197+
198+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
199+
200+
@code {
201+
private int currentCount = 0;
202+
203+
private void IncrementCount()
204+
{
205+
logger.LogWarning("Someone has clicked me!");
206+
207+
currentCount++;
208+
}
209+
}
210+
```
211+
212+
The following example demonstrates logging with an <xref:Microsoft.Extensions.Logging.ILoggerFactory> in Razor components:
213+
214+
```razor
215+
@page "/counter"
216+
@using Microsoft.Extensions.Logging;
217+
@inject ILoggerFactory LoggerFactory
218+
219+
<h1>Counter</h1>
220+
221+
<p>Current count: @currentCount</p>
222+
223+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
224+
225+
@code {
226+
private int currentCount = 0;
227+
228+
private void IncrementCount()
229+
{
230+
var logger = LoggerFactory.CreateLogger<Counter>();
231+
logger.LogWarning("Someone has clicked me!");
232+
233+
currentCount++;
234+
}
235+
}
236+
```
237+
179238
### No asynchronous logger methods
180239

181240
Logging should be so fast that it isn't worth the performance cost of asynchronous code. If your logging data store is slow, don't write to it directly. Consider writing the log messages to a fast store initially, then move them to the slow store later. For example, if you're logging to SQL Server, you don't want to do that directly in a `Log` method, since the `Log` methods are synchronous. Instead, synchronously add log messages to an in-memory queue and have a background worker pull the messages out of the queue to do the asynchronous work of pushing data to SQL Server. For more information, see [this](https://github.com/dotnet/AspNetCore.Docs/issues/11801) GitHub issue.

0 commit comments

Comments
 (0)