Skip to content

Commit ffbc9ae

Browse files
authored
Merge pull request #36661 from dotnet/main
Merge to Live
2 parents bb88f49 + 1a0f300 commit ffbc9ae

54 files changed

Lines changed: 2732 additions & 4196 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

aspnetcore/blazor/fundamentals/logging.md

Lines changed: 4 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: ASP.NET Core Blazor logging
33
author: guardrex
4-
description: Learn about Blazor app logging, including configuration and how to write log messages from Razor components.
4+
description: Learn about Blazor app logging, particularly in client-side logging scenarios.
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: wpickett
77
ms.custom: mvc
@@ -17,7 +17,9 @@ uid: blazor/fundamentals/logging
1717
at the ends of lines to generate a bare return in block quote output.
1818
-->
1919

20-
This article explains Blazor app logging, including configuration and how to write log messages from Razor components.
20+
This article provides information on logging in Blazor apps, particularly in client-side logging scenarios.
21+
22+
For general ASP.NET Core logging guidance, including how to log from Razor components, see <xref:fundamentals/logging/index>.
2123

2224
## Configuration
2325

@@ -38,101 +40,6 @@ When the app is configured in the project file to use implicit namespaces (`<Imp
3840

3941
Log levels conform to ASP.NET Core app log levels, which are listed in the API documentation at <xref:Microsoft.Extensions.Logging.LogLevel>.
4042

41-
## Razor component logging
42-
43-
:::moniker range="< aspnetcore-6.0"
44-
45-
The `using` directive for <xref:Microsoft.Extensions.Logging> is required to support [IntelliSense](/visualstudio/ide/using-intellisense) completions for APIs, such as <xref:Microsoft.Extensions.Logging.LoggerExtensions.LogWarning%2A> and <xref:Microsoft.Extensions.Logging.LoggerExtensions.LogError%2A>.
46-
47-
:::moniker-end
48-
49-
The following example:
50-
51-
* [Injects](xref:blazor/fundamentals/dependency-injection) an <xref:Microsoft.Extensions.Logging.ILogger> (`ILogger<Counter1>`) object to create a logger. The log's *category* is the fully qualified name of the component's type, `Counter`.
52-
* Calls <xref:Microsoft.Extensions.Logging.LoggerExtensions.LogWarning%2A> to log at the <xref:Microsoft.Extensions.Logging.LogLevel.Warning> level.
53-
54-
`Counter1.razor`:
55-
56-
:::moniker range=">= aspnetcore-9.0"
57-
58-
:::code language="razor" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/Components/Pages/Counter1.razor":::
59-
60-
:::moniker-end
61-
62-
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
63-
64-
:::code language="razor" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/Components/Pages/Counter1.razor":::
65-
66-
:::moniker-end
67-
68-
:::moniker range=">= aspnetcore-7.0 < aspnetcore-8.0"
69-
70-
:::code language="razor" source="~/../blazor-samples/7.0/BlazorSample_WebAssembly/Pages/logging/Counter1.razor":::
71-
72-
:::moniker-end
73-
74-
:::moniker range=">= aspnetcore-6.0 < aspnetcore-7.0"
75-
76-
:::code language="razor" source="~/../blazor-samples/6.0/BlazorSample_WebAssembly/Pages/logging/Counter1.razor":::
77-
78-
:::moniker-end
79-
80-
:::moniker range=">= aspnetcore-5.0 < aspnetcore-6.0"
81-
82-
:::code language="razor" source="~/../blazor-samples/5.0/BlazorSample_WebAssembly/Pages/logging/Counter1.razor":::
83-
84-
:::moniker-end
85-
86-
:::moniker range="< aspnetcore-5.0"
87-
88-
:::code language="razor" source="~/../blazor-samples/3.1/BlazorSample_WebAssembly/Pages/logging/Counter1.razor":::
89-
90-
:::moniker-end
91-
92-
The following example demonstrates logging with an <xref:Microsoft.Extensions.Logging.ILoggerFactory> in components.
93-
94-
`Counter2.razor`:
95-
96-
:::moniker range=">= aspnetcore-9.0"
97-
98-
:::code language="razor" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/Components/Pages/Counter2.razor":::
99-
100-
:::moniker-end
101-
102-
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
103-
104-
:::code language="razor" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/Components/Pages/Counter2.razor":::
105-
106-
:::moniker-end
107-
108-
:::moniker range=">= aspnetcore-7.0 < aspnetcore-8.0"
109-
110-
:::code language="razor" source="~/../blazor-samples/7.0/BlazorSample_WebAssembly/Pages/logging/Counter2.razor":::
111-
112-
:::moniker-end
113-
114-
:::moniker range=">= aspnetcore-6.0 < aspnetcore-7.0"
115-
116-
:::code language="razor" source="~/../blazor-samples/6.0/BlazorSample_WebAssembly/Pages/logging/Counter2.razor":::
117-
118-
:::moniker-end
119-
120-
:::moniker range=">= aspnetcore-5.0 < aspnetcore-6.0"
121-
122-
:::code language="razor" source="~/../blazor-samples/5.0/BlazorSample_WebAssembly/Pages/logging/Counter2.razor":::
123-
124-
:::moniker-end
125-
126-
:::moniker range="< aspnetcore-5.0"
127-
128-
:::code language="razor" source="~/../blazor-samples/3.1/BlazorSample_WebAssembly/Pages/logging/Counter2.razor":::
129-
130-
:::moniker-end
131-
132-
## Server-side logging
133-
134-
For general ASP.NET Core logging guidance, see <xref:fundamentals/logging/index>.
135-
13643
## Client-side logging
13744

13845
Not every feature of [ASP.NET Core logging](xref:fundamentals/logging/index) is supported client-side. For example, client-side components don't have access to the client's file system or network, so writing logs to the client's physical or network storage isn't possible. When using a third-party logging service designed to work with single-page apps (SPAs), follow the service's security guidance. Keep in mind that every piece of data, including keys or secrets stored client-side are ***insecure*** and can be easily discovered by malicious users.

aspnetcore/blazor/fundamentals/static-files.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ In releases prior to .NET 8, Blazor framework static files, such as the Blazor s
232232

233233
## Fingerprint client-side static assets in standalone Blazor WebAssembly apps
234234

235-
In standalone Blazor WebAssembly apps during build/publish, the framework overrides placeholders in `index.html` with values computed during build to fingerprint static assets for client-side rendering. A [fingerprint](https://wikipedia.org/wiki/Fingerprint_(computing)) is placed into the `blazor.webassembly.js` script file name, and an import map is generated for other .NET assets.
235+
In standalone Blazor WebAssembly apps during build and publish, the framework overrides placeholders in `index.html` with values computed during build to fingerprint static assets for client-side rendering. A [fingerprint](https://wikipedia.org/wiki/Fingerprint_(computing)) is placed into the `blazor.webassembly.js` script file name, and an import map is generated for other .NET assets.
236236

237237
The following configuration must be present in the `wwwwoot/index.html` file of a standalone Blazor WebAssembly app to adopt fingerprinting:
238238

@@ -262,12 +262,25 @@ In the project file (`.csproj`), the `<OverrideHtmlAssetPlaceholders>` property
262262

263263
When resolving imports for JavaScript interop, the import map is used by the browser resolve fingerprinted files.
264264

265-
Any script in `index.html` with the fingerprint marker is fingerprinted by the framework. For example, a script file named `scripts.js` in the app's `wwwroot/js` folder is fingerprinted by adding `#[.{fingerprint}]` before the file extension (`.js`):
265+
In the following example, all developer-supplied JS files are modules with a `.js` file extension.
266+
267+
A module named `scripts.js` in the app's `wwwroot/js` folder is fingerprinted by adding `#[.{fingerprint}]` before the file extension (`.js`):
266268

267269
```html
268-
<script src="js/scripts#[.{fingerprint}].js"></script>
270+
<script type="module" src="js/scripts#[.{fingerprint}].js"></script>
269271
```
270272

273+
Specify the fingerprint expression with the `<StaticWebAssetFingerprintPattern>` property in the app's project file (`.csproj`):
274+
275+
```xml
276+
<ItemGroup>
277+
<StaticWebAssetFingerprintPattern Include="JSModule" Pattern="*.js"
278+
Expression="#[.{fingerprint}]!" />
279+
</ItemGroup>
280+
```
281+
282+
Any JS file (`*.js`) in `index.html` with the fingerprint marker is fingerprinted by the framework, including when the app is published.
283+
271284
## Fingerprint client-side static assets in Blazor Web Apps
272285

273286
For client-side rendering (CSR) in Blazor Web Apps (Interactive Auto or Interactive WebAssembly render modes), static asset server-side [fingerprinting](https://wikipedia.org/wiki/Fingerprint_(computing)) is enabled by adopting [Map Static Assets routing endpoint conventions (`MapStaticAssets`)](xref:fundamentals/static-files), [`ImportMap` component](xref:blazor/fundamentals/static-files#importmap-component), and the <xref:Microsoft.AspNetCore.Components.ComponentBase.Assets?displayProperty=nameWithType> property (`@Assets["..."]`). For more information, see <xref:fundamentals/static-files>.

aspnetcore/blazor/hybrid/security/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,16 @@ WPF apps use the [Microsoft identity platform](/entra/identity-platform/) to int
5656
* [Quickstart: Set up sign in for a desktop app using Azure Active Directory B2C](/azure/active-directory-b2c/quickstart-native-app-desktop)
5757
* [Configure authentication in a sample WPF desktop app by using Azure AD B2C](/azure/active-directory-b2c/configure-authentication-sample-wpf-desktop-app)
5858

59+
[!INCLUDE[](~/includes/azure-active-directory-b2c-eol-support-notice.md)]
60+
5961
:::zone-end
6062

6163
:::zone pivot="winforms"
6264

6365
Windows Forms apps use the [Microsoft identity platform](/entra/identity-platform/) to integrate with Microsoft Entra (ME-ID) and AAD B2C. For more information, see [Overview of the Microsoft Authentication Library (MSAL)](/entra/identity-platform/msal-overview).
6466

67+
[!INCLUDE[](~/includes/azure-active-directory-b2c-eol-support-notice.md)]
68+
6569
:::zone-end
6670

6771
## Create a custom `AuthenticationStateProvider` without user change updates
@@ -594,12 +598,16 @@ WPF apps use the [Microsoft identity platform](/entra/identity-platform/) to int
594598
* [Quickstart: Set up sign in for a desktop app using Azure Active Directory B2C](/azure/active-directory-b2c/quickstart-native-app-desktop)
595599
* [Configure authentication in a sample WPF desktop app by using Azure AD B2C](/azure/active-directory-b2c/configure-authentication-sample-wpf-desktop-app)
596600

601+
[!INCLUDE[](~/includes/azure-active-directory-b2c-eol-support-notice.md)]
602+
597603
:::zone-end
598604

599605
:::zone pivot="winforms"
600606

601607
Windows Forms apps use the [Microsoft identity platform](/entra/identity-platform/) to integrate with Microsoft Entra (ME-ID) and AAD B2C. For more information, see [Overview of the Microsoft Authentication Library (MSAL)](/entra/identity-platform/msal-overview).
602608

609+
[!INCLUDE[](~/includes/azure-active-directory-b2c-eol-support-notice.md)]
610+
603611
:::zone-end
604612

605613
## Create a custom `AuthenticationStateProvider` without user change updates

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ zone_pivot_groups: blazor-web-app-entra-specification
1717
1818
-->
1919

20+
[!INCLUDE[](~/includes/azure-active-directory-b2c-eol-support-notice.md)]
21+
2022
This article describes how to secure a Blazor Web App with [Microsoft identity platform](/entra/identity-platform/) with [Microsoft Identity Web packages](/entra/msal/dotnet/microsoft-identity-web/) for [Microsoft Entra ID](https://www.microsoft.com/security/business/microsoft-entra) using a sample app.
2123

2224
:::zone pivot="with-yarp-and-aspire"
@@ -1158,7 +1160,7 @@ For more information on how this app secures its weather data, see [Secure data
11581160
* [Microsoft identity platform documentation](/entra/identity-platform/)
11591161
* [Web API documentation | Microsoft identity platform](/entra/identity-platform/index-web-api)
11601162
* [A web API that calls web APIs: Call an API: Option 2: Call a downstream web API with the helper class](/entra/identity-platform/scenario-web-api-call-api-call-api?tabs=aspnetcore#option-2-call-a-downstream-web-api-with-the-helper-class)
1161-
* [`AzureAD/microsoft-identity-web` GitHub repository](https://github.com/AzureAD/microsoft-identity-web/wiki): Helpful guidance on implementing Microsoft Identity Web for Microsoft Entra ID and Azure Active Directory B2C for ASP.NET Core apps, including links to sample apps and related Azure documentation. Currently, Blazor Web Apps aren't explicitly addressed by the Azure documentation, but the setup and configuration of a Blazor Web App for ME-ID and Azure hosting is the same as it is for any ASP.NET Core web app.
1163+
* [`AzureAD/microsoft-identity-web` GitHub repository](https://github.com/AzureAD/microsoft-identity-web/wiki): Helpful guidance on implementing Microsoft Identity Web for Microsoft Entra ID for ASP.NET Core apps, including links to sample apps and related Azure documentation. Currently, Blazor Web Apps aren't explicitly addressed by the Azure documentation, but the setup and configuration of a Blazor Web App for ME-ID and Azure hosting is the same as it is for any ASP.NET Core web app.
11621164
* [`AuthenticationStateProvider` service](xref:blazor/security/index#authenticationstateprovider-service)
11631165
* [Manage authentication state in Blazor Web Apps](xref:blazor/security/index#manage-authentication-state-in-blazor-web-apps)
11641166
* [Service abstractions in Blazor Web Apps](xref:blazor/call-web-api#service-abstractions-for-web-api-calls)

0 commit comments

Comments
 (0)