Update "ASP.NET Core" references (#31783)
parent
4da81958e0
commit
ceab688144
|
@ -18,7 +18,7 @@ This article describes how to call a web API from a Blazor app.
|
|||
[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]
|
||||
|
||||
> [!NOTE]
|
||||
> The code examples in this article adopt [nullable reference types (NRTs) and .NET compiler null-state static analysis](xref:migration/50-to-60#nullable-reference-types-nrts-and-net-compiler-null-state-static-analysis), which are supported in ASP.NET Core 6.0 or later. When targeting ASP.NET Core 5.0 or earlier, remove the null type designation (`?`) from the `string?`, `TodoItem[]?`, `WeatherForecast[]?`, and `IEnumerable<GitHubBranch>?` types in the article's examples.
|
||||
> The code examples in this article adopt [nullable reference types (NRTs) and .NET compiler null-state static analysis](xref:migration/50-to-60#nullable-reference-types-nrts-and-net-compiler-null-state-static-analysis), which are supported in ASP.NET Core in .NET 6 or later. When targeting ASP.NET Core 5.0 or earlier, remove the null type designation (`?`) from the `string?`, `TodoItem[]?`, `WeatherForecast[]?`, and `IEnumerable<GitHubBranch>?` types in the article's examples.
|
||||
|
||||
:::zone pivot="webassembly"
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ This article explains how to flow data from an ancestor Razor component to desce
|
|||
*Cascading values and parameters* provide a convenient way to flow data down a component hierarchy from an ancestor component to any number of descendent components. Unlike [Component parameters](xref:blazor/components/index#component-parameters), cascading values and parameters don't require an attribute assignment for each descendent component where the data is consumed. Cascading values and parameters also allow components to coordinate with each other across a component hierarchy.
|
||||
|
||||
> [!NOTE]
|
||||
> The code examples in this article adopt [nullable reference types (NRTs) and .NET compiler null-state static analysis](xref:migration/50-to-60#nullable-reference-types-nrts-and-net-compiler-null-state-static-analysis), which are supported in ASP.NET Core 6.0 or later. When targeting ASP.NET Core 5.0 or earlier, remove the null type designation (`?`) from the `CascadingType?`, `@ActiveTab?`, `RenderFragment?`, `ITab?`, `TabSet?`, and `string?` types in the article's examples.
|
||||
> The code examples in this article adopt [nullable reference types (NRTs) and .NET compiler null-state static analysis](xref:migration/50-to-60#nullable-reference-types-nrts-and-net-compiler-null-state-static-analysis), which are supported in ASP.NET Core in .NET 6 or later. When targeting ASP.NET Core 5.0 or earlier, remove the null type designation (`?`) from the `CascadingType?`, `@ActiveTab?`, `RenderFragment?`, `ITab?`, `TabSet?`, and `string?` types in the article's examples.
|
||||
|
||||
[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]
|
||||
|
||||
|
|
|
@ -289,7 +289,7 @@ Two-way data binding isn't possible to implement with an event handler. Use `@bi
|
|||
|
||||
The `OnInput` event handler updates the value of `inputValue` to `Long!` after a fourth character is provided. However, the user can continue adding characters to the element value in the UI. The value of `inputValue` isn't bound back to the element's value with each keystroke. The preceding example is only capable of one-way data binding.
|
||||
|
||||
The reason for this behavior is that Blazor isn't aware that your code intends to modify the value of `inputValue` in the event handler. Blazor doesn't try to force DOM element values and .NET variable values to match unless they're bound with `@bind` syntax. In earlier versions of Blazor, two-way data binding is implemented by [binding the element to a property and controlling the property's value with its setter](#binding-to-a-property-with-c-get-and-set-accessors). In ASP.NET Core 7.0 or later, `@bind:get`/`@bind:set` modifier syntax is used to implement two-way data binding, as the next example demonstrates.
|
||||
The reason for this behavior is that Blazor isn't aware that your code intends to modify the value of `inputValue` in the event handler. Blazor doesn't try to force DOM element values and .NET variable values to match unless they're bound with `@bind` syntax. In earlier versions of Blazor, two-way data binding is implemented by [binding the element to a property and controlling the property's value with its setter](#binding-to-a-property-with-c-get-and-set-accessors). In ASP.NET Core in .NET 7 or later, `@bind:get`/`@bind:set` modifier syntax is used to implement two-way data binding, as the next example demonstrates.
|
||||
|
||||
<span aria-hidden="true">✔️</span> Consider the following ***correct approach*** using `@bind:get`/`@bind:set` for two-way data binding:
|
||||
|
||||
|
@ -364,7 +364,7 @@ Using `@bind:get`/`@bind:set` modifiers both controls the underlying value of `i
|
|||
:::moniker range="< aspnetcore-7.0"
|
||||
|
||||
> [!NOTE]
|
||||
> Two-way binding to a property with `get`/`set` accessors requires discarding the <xref:System.Threading.Tasks.Task> returned by <xref:Microsoft.AspNetCore.Components.EventCallback.InvokeAsync%2A?displayProperty=nameWithType>. For two-way data binding in ASP.NET Core 7.0 or later, we recommend using `@bind:get`/`@bind:set` modifiers, which are described in 7.0 or later versions of this article.
|
||||
> Two-way binding to a property with `get`/`set` accessors requires discarding the <xref:System.Threading.Tasks.Task> returned by <xref:Microsoft.AspNetCore.Components.EventCallback.InvokeAsync%2A?displayProperty=nameWithType>. For two-way data binding in ASP.NET Core in .NET 7 or later, we recommend using `@bind:get`/`@bind:set` modifiers, which are described in 7.0 or later versions of this article.
|
||||
|
||||
:::moniker-end
|
||||
|
||||
|
|
|
@ -308,7 +308,7 @@ The following controller in the web API project saves uploaded files from the cl
|
|||
:::moniker range="= aspnetcore-6.0"
|
||||
|
||||
> [!NOTE]
|
||||
> Binding form values with the [`[FromForm]` attribute](xref:Microsoft.AspNetCore.Mvc.FromFormAttribute) isn't natively supported for [Minimal APIs](xref:fundamentals/minimal-apis?view=aspnetcore-6.0#explicit-parameter-binding) in ASP.NET Core 6.0. Therefore, the following `Filesave` controller example can't be converted to use Minimal APIs. Support for binding from form values with Minimal APIs is available in ASP.NET Core 7.0 or later.
|
||||
> Binding form values with the [`[FromForm]` attribute](xref:Microsoft.AspNetCore.Mvc.FromFormAttribute) isn't natively supported for [Minimal APIs](xref:fundamentals/minimal-apis?view=aspnetcore-6.0#explicit-parameter-binding) in ASP.NET Core in .NET 6. Therefore, the following `Filesave` controller example can't be converted to use Minimal APIs. Support for binding from form values with Minimal APIs is available in ASP.NET Core in .NET 7 or later.
|
||||
|
||||
:::moniker-end
|
||||
|
||||
|
@ -520,7 +520,7 @@ The following controller in the server-side project saves uploaded files from th
|
|||
:::moniker range="< aspnetcore-6.0"
|
||||
|
||||
> [!NOTE]
|
||||
> Binding form values with the [`[FromForm]` attribute](xref:Microsoft.AspNetCore.Mvc.FromFormAttribute) isn't natively supported for [Minimal APIs](xref:fundamentals/minimal-apis?view=aspnetcore-6.0#explicit-parameter-binding) in ASP.NET Core 6.0. Therefore, the following `Filesave` controller example can't be converted to use Minimal APIs. Support for binding from form values with Minimal APIs is available in ASP.NET Core 7.0 or later.
|
||||
> Binding form values with the [`[FromForm]` attribute](xref:Microsoft.AspNetCore.Mvc.FromFormAttribute) isn't natively supported for [Minimal APIs](xref:fundamentals/minimal-apis?view=aspnetcore-6.0#explicit-parameter-binding) in ASP.NET Core in .NET 6. Therefore, the following `Filesave` controller example can't be converted to use Minimal APIs. Support for binding from form values with Minimal APIs is available in ASP.NET Core in .NET 7 or later.
|
||||
|
||||
:::moniker-end
|
||||
|
||||
|
|
|
@ -310,7 +310,7 @@ Examples use the [target-typed `new` operator](/dotnet/csharp/language-reference
|
|||
public ShipDescription ShipDescription { get; set; } = new();
|
||||
```
|
||||
|
||||
If using C# 8.0 or earlier (.NET 3.1), modify the example code to state the type to the `new` operator:
|
||||
If using C# 8.0 or earlier (ASP.NET Core 3.1), modify the example code to state the type to the `new` operator:
|
||||
|
||||
```csharp
|
||||
public ShipDescription ShipDescription { get; set; } = new ShipDescription();
|
||||
|
|
|
@ -543,7 +543,7 @@ For more information, see <xref:blazor/blazor-ef-core>.
|
|||
|
||||
[Circuit activity handlers](xref:blazor/fundamentals/signalr#monitor-server-side-circuit-activity) provide an approach for accessing scoped Blazor services from other non-Blazor dependency injection (DI) scopes, such as scopes created using <xref:System.Net.Http.IHttpClientFactory>.
|
||||
|
||||
Prior to the release of ASP.NET Core 8.0, accessing circuit-scoped services from other dependency injection scopes required using a custom base component type. With circuit activity handlers, a custom base component type isn't required, as the following example demonstrates:
|
||||
Prior to the release of ASP.NET Core in .NET 8, accessing circuit-scoped services from other dependency injection scopes required using a custom base component type. With circuit activity handlers, a custom base component type isn't required, as the following example demonstrates:
|
||||
|
||||
```csharp
|
||||
public class CircuitServicesAccessor
|
||||
|
|
|
@ -733,7 +733,7 @@ Blazor Web App:
|
|||
</script>
|
||||
```
|
||||
|
||||
The following example for the `Pages/_Host.cshtml` file (Blazor Server, all versions except ASP.NET Core 6.0) or `Pages/_Layout.cshtml` file (Blazor Server, ASP.NET Core 6.0).
|
||||
The following example for the `Pages/_Host.cshtml` file (Blazor Server, all versions except ASP.NET Core in .NET 6) or `Pages/_Layout.cshtml` file (Blazor Server, ASP.NET Core in .NET 6).
|
||||
|
||||
Blazor Server:
|
||||
|
||||
|
@ -777,7 +777,7 @@ Configure the following values for the client:
|
|||
* `serverTimeoutInMilliseconds`: The server timeout in milliseconds. If this timeout elapses without receiving any messages from the server, the connection is terminated with an error. The default timeout value is 30 seconds. The server timeout should be at least double the value assigned to the Keep-Alive interval (`keepAliveIntervalInMilliseconds`).
|
||||
* `keepAliveIntervalInMilliseconds`: Default interval at which to ping the server. This setting allows the server to detect hard disconnects, such as when a client unplugs their computer from the network. The ping occurs at most as often as the server pings. If the server pings every five seconds, assigning a value lower than `5000` (5 seconds) pings every five seconds. The default value is 15 seconds. The Keep-Alive interval should be less than or equal to half the value assigned to the server timeout (`serverTimeoutInMilliseconds`).
|
||||
|
||||
The following example for the `Pages/_Host.cshtml` file (Blazor Server, all versions except ASP.NET Core 6.0) or `Pages/_Layout.cshtml` file (Blazor Server, ASP.NET Core 6.0):
|
||||
The following example for the `Pages/_Host.cshtml` file (Blazor Server, all versions except ASP.NET Core in .NET 6) or `Pages/_Layout.cshtml` file (Blazor Server, ASP.NET Core in .NET 6):
|
||||
|
||||
```html
|
||||
<script src="{BLAZOR SCRIPT}" autostart="false"></script>
|
||||
|
|
|
@ -44,7 +44,7 @@ In this article, *language* refers to selections made by a user in their browser
|
|||
*Culture* pertains to members of .NET and Blazor API. For example, a user's request can include the [`Accept-Language` header](https://developer.mozilla.org/docs/Web/HTTP/Headers/Accept-Language) specifying a *language* from the user's perspective, but the app ultimately sets the <xref:System.Globalization.CultureInfo.CurrentCulture> ("culture") property from the language that the user requested. API usually uses the word "culture" in its member names.
|
||||
|
||||
> [!NOTE]
|
||||
> The code examples in this article adopt [nullable reference types (NRTs) and .NET compiler null-state static analysis](xref:migration/50-to-60#nullable-reference-types-nrts-and-net-compiler-null-state-static-analysis), which are supported in ASP.NET Core 6.0 or later. When targeting ASP.NET Core 5.0 or earlier, remove the null type designation (`?`) from the article's examples.
|
||||
> The code examples in this article adopt [nullable reference types (NRTs) and .NET compiler null-state static analysis](xref:migration/50-to-60#nullable-reference-types-nrts-and-net-compiler-null-state-static-analysis), which are supported in ASP.NET Core in .NET 6 or later. When targeting ASP.NET Core 5.0 or earlier, remove the null type designation (`?`) from the article's examples.
|
||||
|
||||
## Globalization
|
||||
|
||||
|
|
|
@ -985,7 +985,7 @@ Blazor performs Intermediate Language (IL) linking on each Release build to remo
|
|||
|
||||
## Change the file name extension of DLL files
|
||||
|
||||
*This section applies to ASP.NET Core 6.x and 7.x. In ASP.NET Core 8.0 or later, .NET assemblies are deployed as WebAssembly files (`.wasm`) using the Webcil file format. In ASP.NET Core 8.0 or later, this section only applies if the Webcil file format has been disabled in the app's project file.*
|
||||
*This section applies to ASP.NET Core 6.x and 7.x. In ASP.NET Core in .NET 8 or later, .NET assemblies are deployed as WebAssembly files (`.wasm`) using the Webcil file format. In ASP.NET Core in .NET 8 or later, this section only applies if the Webcil file format has been disabled in the app's project file.*
|
||||
|
||||
If a firewall, anti-virus program, or network security appliance is blocking the transmission of the app's dynamic-link library (DLL) files (`.dll`), you can follow the guidance in this section to change the file name extensions of the app's published DLL files.
|
||||
|
||||
|
@ -996,7 +996,7 @@ If a firewall, anti-virus program, or network security appliance is blocking the
|
|||
> [!NOTE]
|
||||
> Changing the file name extensions of the app's DLL files might not resolve the problem because many security systems scan the content of the app's files, not merely check file extensions.
|
||||
>
|
||||
> For a more robust approach in environments that block the download and execution of DLL files, use ASP.NET Core 8.0 or later, which by default packages .NET assemblies as WebAssembly files (`.wasm`) using the [Webcil](https://github.com/dotnet/runtime/blob/main/docs/design/mono/webcil.md) file format. For more information, see the *Webcil packaging format for .NET assemblies* section in an 8.0 or later version of this article.
|
||||
> For a more robust approach in environments that block the download and execution of DLL files, use ASP.NET Core in .NET 8 or later, which by default packages .NET assemblies as WebAssembly files (`.wasm`) using the [Webcil](https://github.com/dotnet/runtime/blob/main/docs/design/mono/webcil.md) file format. For more information, see the *Webcil packaging format for .NET assemblies* section in an 8.0 or later version of this article.
|
||||
>
|
||||
> Third-party approaches exist for dealing with this problem. For more information, see the resources at [Awesome Blazor](https://github.com/AdrienTorris/awesome-blazor).
|
||||
|
||||
|
@ -1009,8 +1009,8 @@ If a firewall, anti-virus program, or network security appliance is blocking the
|
|||
>
|
||||
> For a more robust approach in environments that block the download and execution of DLL files, take ***either*** of the following approaches:
|
||||
>
|
||||
> * Use ASP.NET Core 8.0 or later, which by default packages .NET assemblies as WebAssembly files (`.wasm`) using the [Webcil](https://github.com/dotnet/runtime/blob/main/docs/design/mono/webcil.md) file format. For more information, see the *Webcil packaging format for .NET assemblies* section in an 8.0 or later version of this article.
|
||||
> * In ASP.NET Core 6.0 or later, use a [custom deployment layout](xref:blazor/host-and-deploy/webassembly-deployment-layout).
|
||||
> * Use ASP.NET Core in .NET 8 or later, which by default packages .NET assemblies as WebAssembly files (`.wasm`) using the [Webcil](https://github.com/dotnet/runtime/blob/main/docs/design/mono/webcil.md) file format. For more information, see the *Webcil packaging format for .NET assemblies* section in an 8.0 or later version of this article.
|
||||
> * In ASP.NET Core in .NET 6 or later, use a [custom deployment layout](xref:blazor/host-and-deploy/webassembly-deployment-layout).
|
||||
>
|
||||
> Third-party approaches exist for dealing with this problem. For more information, see the resources at [Awesome Blazor](https://github.com/AdrienTorris/awesome-blazor).
|
||||
|
||||
|
@ -1070,7 +1070,7 @@ To address the compressed `blazor.boot.json.gz` and `blazor.boot.json.br` files,
|
|||
|
||||
The preceding guidance for the compressed `blazor.boot.json` file also applies when service worker assets are in use. Remove or recompress `service-worker-assets.js.br` and `service-worker-assets.js.gz`. Otherwise, file integrity checks fail in the browser.
|
||||
|
||||
The following Windows example for .NET 6.0 uses a PowerShell script placed at the root of the project. The following script, which disables compression, is the basis for further modification if you wish to recompress the `blazor.boot.json` file.
|
||||
The following Windows example for .NET 6 uses a PowerShell script placed at the root of the project. The following script, which disables compression, is the basis for further modification if you wish to recompress the `blazor.boot.json` file.
|
||||
|
||||
`ChangeDLLExtensions.ps1:`:
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ Select the **.NET MAUI Blazor Hybrid App** template and then select the **Next**
|
|||
:::image type="content" source="maui/_static/win/new-project-2.png" alt-text="Choose a template.":::
|
||||
|
||||
> [!NOTE]
|
||||
> In .NET 7.0 or earlier, the template is named **.NET MAUI Blazor App**.
|
||||
> In .NET 7 or earlier, the template is named **.NET MAUI Blazor App**.
|
||||
|
||||
In the **Configure your new project** dialog:
|
||||
|
||||
|
|
|
@ -28,11 +28,11 @@ This article describes an alternative JS interop approach specific to client-sid
|
|||
|
||||
## Obsolete JavaScript interop API
|
||||
|
||||
Unmarshalled JS interop using <xref:Microsoft.JSInterop.IJSUnmarshalledRuntime> API is obsolete in ASP.NET Core 7.0 or later. Follow the guidance in this article to replace the obsolete API.
|
||||
Unmarshalled JS interop using <xref:Microsoft.JSInterop.IJSUnmarshalledRuntime> API is obsolete in ASP.NET Core in .NET 7 or later. Follow the guidance in this article to replace the obsolete API.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
[Download and install .NET 7.0 or later](https://dotnet.microsoft.com/download/dotnet) if it isn't already installed on the system or if the system doesn't have the latest version installed.
|
||||
[Download and install .NET 7 or later](https://dotnet.microsoft.com/download/dotnet) if it isn't already installed on the system or if the system doesn't have the latest version installed.
|
||||
|
||||
## Namespace
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ Further JS interop guidance is provided in the following articles:
|
|||
:::moniker range=">= aspnetcore-7.0"
|
||||
|
||||
> [!NOTE]
|
||||
> JavaScript `[JSImport]`/`[JSExport]` interop API is available for client-side components in ASP.NET Core 7.0 or later.
|
||||
> JavaScript `[JSImport]`/`[JSExport]` interop API is available for client-side components in ASP.NET Core in .NET 7 or later.
|
||||
>
|
||||
> For more information, see <xref:blazor/js-interop/import-export-interop>.
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ uid: blazor/performance
|
|||
Blazor is optimized for high performance in most realistic application UI scenarios. However, the best performance depends on developers adopting the correct patterns and features.
|
||||
|
||||
> [!NOTE]
|
||||
> The code examples in this article adopt [nullable reference types (NRTs) and .NET compiler null-state static analysis](xref:migration/50-to-60#nullable-reference-types-nrts-and-net-compiler-null-state-static-analysis), which are supported in ASP.NET Core 6.0 or later.
|
||||
> The code examples in this article adopt [nullable reference types (NRTs) and .NET compiler null-state static analysis](xref:migration/50-to-60#nullable-reference-types-nrts-and-net-compiler-null-state-static-analysis), which are supported in ASP.NET Core in .NET 6 or later.
|
||||
|
||||
[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]
|
||||
|
||||
|
@ -736,7 +736,7 @@ function jsInteropCall() {
|
|||
|
||||
### Use JavaScript `[JSImport]`/`[JSExport]` interop
|
||||
|
||||
JavaScript `[JSImport]`/`[JSExport]` interop for Blazor WebAssembly apps offers improved performance and stability over the JS interop API in framework releases prior to ASP.NET Core 7.0.
|
||||
JavaScript `[JSImport]`/`[JSExport]` interop for Blazor WebAssembly apps offers improved performance and stability over the JS interop API in framework releases prior to ASP.NET Core in .NET 7.
|
||||
|
||||
For more information, see <xref:blazor/js-interop/import-export-interop>.
|
||||
|
||||
|
|
|
@ -300,7 +300,7 @@ By default, this manifest lists:
|
|||
* Any Blazor-managed resources, such as .NET assemblies and the .NET WebAssembly runtime files required to function offline.
|
||||
* All resources for publishing to the app's `wwwroot` directory, such as images, stylesheets, and JavaScript files, including static web assets supplied by external projects and NuGet packages.
|
||||
|
||||
You can control which of these resources are fetched and cached by the service worker by editing the logic in `onInstall` in `service-worker.published.js`. By default, the service worker fetches and caches files matching typical web file name extensions such as `.html`, `.css`, `.js`, and `.wasm`, plus file types specific to Blazor WebAssembly, such as `.pdb` files (all versions) and `.dll` files (ASP.NET Core 7.0 or earlier).
|
||||
You can control which of these resources are fetched and cached by the service worker by editing the logic in `onInstall` in `service-worker.published.js`. By default, the service worker fetches and caches files matching typical web file name extensions such as `.html`, `.css`, `.js`, and `.wasm`, plus file types specific to Blazor WebAssembly, such as `.pdb` files (all versions) and `.dll` files (ASP.NET Core in .NET 7 or earlier).
|
||||
|
||||
To include additional resources that aren't present in the app's `wwwroot` directory, define extra MSBuild `ItemGroup` entries, as shown in the following example:
|
||||
|
||||
|
|
|
@ -350,7 +350,7 @@ Project structure:
|
|||
* `MainLayout.razor.css`: Stylesheet for the app's main layout.
|
||||
* `NavMenu` component (`NavMenu.razor`): Implements sidebar navigation. Includes the [`NavLink` component](xref:blazor/fundamentals/routing#navlink-component) (<xref:Microsoft.AspNetCore.Components.Routing.NavLink>), which renders navigation links to other Razor components. The <xref:Microsoft.AspNetCore.Components.Routing.NavLink> component automatically indicates a selected state when its component is loaded, which helps the user understand which component is currently displayed.
|
||||
* `NavMenu.razor.css`: Stylesheet for the app's navigation menu.
|
||||
* `SurveyPrompt` component (`SurveyPrompt.razor`) (*ASP.NET Core 7.0 or earlier*): Blazor survey component.
|
||||
* `SurveyPrompt` component (`SurveyPrompt.razor`) (*ASP.NET Core in .NET 7 or earlier*): Blazor survey component.
|
||||
|
||||
* `wwwroot` folder: The [Web Root](xref:fundamentals/index#web-root) folder for the app containing the app's public static assets, including `appsettings.json` and environmental app settings files for [configuration settings](xref:blazor/fundamentals/configuration). The `index.html` webpage is the root page of the app implemented as an HTML page:
|
||||
* When any page of the app is initially requested, this page is rendered and returned in the response.
|
||||
|
|
|
@ -18,4 +18,4 @@ The <xref:Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthe
|
|||
```
|
||||
|
||||
> [!NOTE]
|
||||
> [Nullable reference types (NRTs) and .NET compiler null-state static analysis](xref:migration/50-to-60#nullable-reference-types-nrts-and-net-compiler-null-state-static-analysis) is supported in ASP.NET Core 6.0 or later. Prior to the release of ASP.NET Core 6.0, the `string` type appears without the null type designation (`?`).
|
||||
> [Nullable reference types (NRTs) and .NET compiler null-state static analysis](xref:migration/50-to-60#nullable-reference-types-nrts-and-net-compiler-null-state-static-analysis) is supported in ASP.NET Core in .NET 6 or later. Prior to the release of ASP.NET Core in .NET 6, the `string` type appears without the null type designation (`?`).
|
||||
|
|
|
@ -13,8 +13,8 @@ If the request was successful, the token variable is populated with the access t
|
|||
|
||||
If the request failed because the token couldn't be provisioned without user interaction:
|
||||
|
||||
* ASP.NET Core 7.0 or later: The app navigates to `AccessTokenResult.InteractiveRequestUrl` using the given `AccessTokenResult.InteractionOptions` to allow refreshing the access token.
|
||||
* ASP.NET Core 6.0 or earlier: The token result contains a redirect URL. Navigating to this URL takes the user to the login page and back to the current page after a successful authentication.
|
||||
* ASP.NET Core in .NET 7 or later: The app navigates to `AccessTokenResult.InteractiveRequestUrl` using the given `AccessTokenResult.InteractionOptions` to allow refreshing the access token.
|
||||
* ASP.NET Core in .NET 6 or earlier: The token result contains a redirect URL. Navigating to this URL takes the user to the login page and back to the current page after a successful authentication.
|
||||
|
||||
```razor
|
||||
@page "/fetchdata"
|
||||
|
|
|
@ -2,8 +2,8 @@ The `RedirectToLogin` component (`Shared/RedirectToLogin.razor`):
|
|||
|
||||
* Manages redirecting unauthorized users to the login page.
|
||||
* The current URL that the user is attempting to access is maintained by so that they can be returned to that page if authentication is successful using:
|
||||
* [Navigation history state](xref:blazor/fundamentals/routing#navigation-history-state) in ASP.NET Core 7.0 or later.
|
||||
* A query string in ASP.NET Core 6.0 or earlier.
|
||||
* [Navigation history state](xref:blazor/fundamentals/routing#navigation-history-state) in ASP.NET Core in .NET 7 or later.
|
||||
* A query string in ASP.NET Core in .NET 6 or earlier.
|
||||
|
||||
Inspect the `RedirectToLogin` component in [reference source](https://github.com/dotnet/aspnetcore/blob/release/7.0/src/ProjectTemplates/Web.ProjectTemplates/content/ComponentsWebAssembly-CSharp/Client/Shared/RedirectToLogin.razor).
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
### Logging
|
||||
|
||||
*This section applies to ASP.NET Core 7.0 or later.*
|
||||
*This section applies to ASP.NET Core in .NET 7 or later.*
|
||||
|
||||
To enable debug or trace logging for Blazor WebAssembly authentication, see <xref:blazor/fundamentals/logging>.
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ Set the user identifier claim type when a Server app requires:
|
|||
* <xref:Microsoft.AspNetCore.Identity.UserManager%601> or <xref:Microsoft.AspNetCore.Identity.SignInManager%601> in an API endpoint.
|
||||
* <xref:Microsoft.AspNetCore.Identity.IdentityUser> details, such as the user's name, email address, or lockout end time.
|
||||
|
||||
In `Program.cs` for ASP.NET Core 6.0 or later:
|
||||
In `Program.cs` for ASP.NET Core in .NET 6 or later:
|
||||
|
||||
```csharp
|
||||
using System.Security.Claims;
|
||||
|
|
|
@ -44,7 +44,7 @@ ASP.NET Core abstractions, such as <xref:Microsoft.AspNetCore.Identity.SignInMan
|
|||
:::moniker-end
|
||||
|
||||
> [!NOTE]
|
||||
> The code examples in this article adopt [nullable reference types (NRTs) and .NET compiler null-state static analysis](xref:migration/50-to-60#nullable-reference-types-nrts-and-net-compiler-null-state-static-analysis), which are supported in ASP.NET Core 6.0 or later. When targeting ASP.NET Core 5.0 or earlier, remove the null type designation (`?`) from examples in this article.
|
||||
> The code examples in this article adopt [nullable reference types (NRTs) and .NET compiler null-state static analysis](xref:migration/50-to-60#nullable-reference-types-nrts-and-net-compiler-null-state-static-analysis), which are supported in ASP.NET Core in .NET 6 or later. When targeting ASP.NET Core 5.0 or earlier, remove the null type designation (`?`) from examples in this article.
|
||||
|
||||
:::moniker range=">= aspnetcore-8.0"
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ This article explains how to configure server-side Blazor for additional securit
|
|||
[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]
|
||||
|
||||
> [!NOTE]
|
||||
> The code examples in this article adopt [nullable reference types (NRTs) and .NET compiler null-state static analysis](xref:migration/50-to-60#nullable-reference-types-nrts-and-net-compiler-null-state-static-analysis), which are supported in ASP.NET Core 6.0 or later. When targeting ASP.NET Core 5.0 or earlier, remove the null type designation (`?`) from the `string?`, `TodoItem[]?`, `WeatherForecast[]?`, and `IEnumerable<GitHubBranch>?` types in the article's examples.
|
||||
> The code examples in this article adopt [nullable reference types (NRTs) and .NET compiler null-state static analysis](xref:migration/50-to-60#nullable-reference-types-nrts-and-net-compiler-null-state-static-analysis), which are supported in ASP.NET Core in .NET 6 or later. When targeting ASP.NET Core 5.0 or earlier, remove the null type designation (`?`) from the `string?`, `TodoItem[]?`, `WeatherForecast[]?`, and `IEnumerable<GitHubBranch>?` types in the article's examples.
|
||||
|
||||
## Pass tokens to a server-side Blazor app
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ Blazor differs from a traditional server-rendered web apps that make new HTTP re
|
|||
> Implementing a custom `NavigationManager` to achieve authentication validation during navigation isn't recommended. If the app must execute custom authentication state logic during navigation, use a [custom `AuthenticationStateProvider`](#implement-a-custom-authenticationstateprovider).
|
||||
|
||||
> [!NOTE]
|
||||
> The code examples in this article adopt [nullable reference types (NRTs) and .NET compiler null-state static analysis](xref:migration/50-to-60#nullable-reference-types-nrts-and-net-compiler-null-state-static-analysis), which are supported in ASP.NET Core 6.0 or later. When targeting ASP.NET Core 5.0 or earlier, remove the null type designation (`?`) from the examples in this article.
|
||||
> The code examples in this article adopt [nullable reference types (NRTs) and .NET compiler null-state static analysis](xref:migration/50-to-60#nullable-reference-types-nrts-and-net-compiler-null-state-static-analysis), which are supported in ASP.NET Core in .NET 6 or later. When targeting ASP.NET Core 5.0 or earlier, remove the null type designation (`?`) from the examples in this article.
|
||||
|
||||
## Project template
|
||||
|
||||
|
|
|
@ -1600,7 +1600,7 @@ The following subsections explain how to replace:
|
|||
Create a JavaScript library to handle your custom authentication details.
|
||||
|
||||
> [!WARNING]
|
||||
> The guidance in this section is an implementation detail of the default <xref:Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationService%603>. The TypeScript code in this section applies specifically to ASP.NET Core 7.0 and is subject to change without notice in upcoming releases of ASP.NET Core.
|
||||
> The guidance in this section is an implementation detail of the default <xref:Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationService%603>. The TypeScript code in this section applies specifically to ASP.NET Core in .NET 7 and is subject to change without notice in upcoming releases of ASP.NET Core.
|
||||
|
||||
```typescript
|
||||
// .NET makes calls to an AuthenticationService object in the Window.
|
||||
|
|
|
@ -181,7 +181,7 @@ When these scenarios are implemented in documentation examples, ***two*** identi
|
|||
|
||||
Although refresh tokens can't be secured in Blazor WebAssembly apps, they can be used if you implement them with appropriate security strategies.
|
||||
|
||||
For standalone Blazor WebAssembly apps in ASP.NET Core 6.0 or later, we recommend using:
|
||||
For standalone Blazor WebAssembly apps in ASP.NET Core in .NET 6 or later, we recommend using:
|
||||
|
||||
* The [OAuth 2.0 Authorization Code flow (Code) with Proof Key for Code Exchange (PKCE)](https://oauth.net/2/pkce/).
|
||||
* A refresh token that has a short expiration.
|
||||
|
@ -279,7 +279,7 @@ For more information, see <xref:signalr/authn-and-authz#bearer-token-authenticat
|
|||
|
||||
## Logging
|
||||
|
||||
*This section applies to Blazor WebAssembly apps in ASP.NET Core 7.0 or later.*
|
||||
*This section applies to Blazor WebAssembly apps in ASP.NET Core in .NET 7 or later.*
|
||||
|
||||
To enable debug or trace logging, see the *Authentication logging (Blazor WebAssembly)* section in a 7.0 or later version of the <xref:blazor/fundamentals/logging> article.
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ zone_pivot_groups: blazor-app-models
|
|||
This article describes common approaches for maintaining a user's data (state) while they use an app and across browser sessions.
|
||||
|
||||
> [!NOTE]
|
||||
> The code examples in this article adopt [nullable reference types (NRTs) and .NET compiler null-state static analysis](xref:migration/50-to-60#nullable-reference-types-nrts-and-net-compiler-null-state-static-analysis), which are supported in ASP.NET Core 6.0 or later. When targeting ASP.NET Core 5.0 or earlier, remove the null type designation (`?`) from types in the article's examples.
|
||||
> The code examples in this article adopt [nullable reference types (NRTs) and .NET compiler null-state static analysis](xref:migration/50-to-60#nullable-reference-types-nrts-and-net-compiler-null-state-static-analysis), which are supported in ASP.NET Core in .NET 6 or later. When targeting ASP.NET Core 5.0 or earlier, remove the null type designation (`?`) from types in the article's examples.
|
||||
|
||||
[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]
|
||||
|
||||
|
@ -697,7 +697,7 @@ Client-side apps (`Program` file):
|
|||
builder.Services.AddSingleton<StateContainer>();
|
||||
```
|
||||
|
||||
Server-side apps (`Program` file, ASP.NET Core 6.0 or later):
|
||||
Server-side apps (`Program` file, ASP.NET Core in .NET 6 or later):
|
||||
|
||||
```csharp
|
||||
builder.Services.AddScoped<StateContainer>();
|
||||
|
|
|
@ -72,7 +72,7 @@ Select the **Blazor Web App** template. Select **Next**.
|
|||
|
||||
Type `BlazorSignalRApp` in the **Project name** field. Confirm the **Location** entry is correct or provide a location for the project. Select **Next**.
|
||||
|
||||
Confirm the **Framework** is .NET 8.0 or later. Select **Create**.
|
||||
Confirm the **Framework** is .NET 8 or later. Select **Create**.
|
||||
|
||||
# [Visual Studio Code](#tab/visual-studio-code)
|
||||
|
||||
|
|
Loading…
Reference in New Issue