diff --git a/aspnetcore/blazor/components/built-in-components.md b/aspnetcore/blazor/components/built-in-components.md index 2bd4b5fcdf9c..05470eb88d2e 100644 --- a/aspnetcore/blazor/components/built-in-components.md +++ b/aspnetcore/blazor/components/built-in-components.md @@ -27,7 +27,7 @@ The following built-in Razor components are provided by the Blazor framework. Fo * [`FocusOnNavigate`](xref:blazor/fundamentals/routing#focus-an-element-on-navigation) * [`HeadContent`](xref:blazor/components/control-head-content) * [`HeadOutlet`](xref:blazor/components/control-head-content) -* [`ImportMap`](xref:blazor/fundamentals/static-files#import-maps) +* [`ImportMap`](xref:blazor/fundamentals/static-files#importmap-component) * [`InputCheckbox`](xref:blazor/forms/input-components) * [`InputDate`](xref:blazor/forms/input-components) * [`InputFile`](xref:blazor/file-uploads) diff --git a/aspnetcore/blazor/fundamentals/environments.md b/aspnetcore/blazor/fundamentals/environments.md index eb33daa9f157..c79dc4f34594 100644 --- a/aspnetcore/blazor/fundamentals/environments.md +++ b/aspnetcore/blazor/fundamentals/environments.md @@ -28,34 +28,58 @@ We recommend the following conventions: ## Set the environment -:::moniker range=">= aspnetcore-8.0" - The environment is set using any of the following approaches: -* Blazor Web App: Use any of the approaches described in for general ASP.NET Core apps. -* Blazor Web App or standalone Blazor WebAssembly: [Blazor start configuration](#set-the-client-side-environment-via-blazor-startup-configuration) -* Standalone Blazor WebAssembly: [`Blazor-Environment` header](#set-the-client-side-environment-via-header) -* Blazor Web App or standalone Blazor WebAssembly: [Azure App Service](#set-the-environment-for-azure-app-service) +:::moniker range=">= aspnetcore-10.0" + +* Blazor Web App or Blazor Server: Use any of the approaches described in for general ASP.NET Core apps. +* Any Blazor app: [Blazor start configuration](#set-the-client-side-environment-via-blazor-startup-configuration) +* Standalone Blazor WebAssembly: `` property + +On the client for a Blazor Web App, the environment is determined from the server via an HTML comment that developers don't interact with: + +```html + +``` + +For a standalone Blazor WebAssembly app, set the environment with the `` property in the app's project file (`.csproj`). The following example sets the `Staging` environment: + +```xml +Staging +``` + +The default environments are `Development` for build and `Production` for publish. + +:::moniker-end + +:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0" + +* Blazor Web App or Blazor Server: Use any of the approaches described in for general ASP.NET Core apps. +* Any Blazor app: + * [Blazor start configuration](#set-the-client-side-environment-via-blazor-startup-configuration) + * [Azure App Service](#set-the-environment-for-azure-app-service) +* Blazor WebAssembly: [`Blazor-Environment` header](#set-the-client-side-environment-via-header) On the client for a Blazor Web App, the environment is determined from the server via a middleware that communicates the environment to the browser via a header named `Blazor-Environment`. The header sets the environment when the is created in the client-side `Program` file (). +For a standalone Blazor WebAssembly app running locally, the development server adds the `Blazor-Environment` header with the environment name obtained from the hosting environment. The hosting environment sets the environment from the `ASPNETCORE_ENVIRONMENT` environment variable established by the project's `Properties/launchSettings.json` file. The default value of the environment variable in a project created from the Blazor WebAssembly project template is `Development`. For more information, see the [Set the client-side environment via header](#set-the-client-side-environment-via-header) section. + :::moniker-end :::moniker range="< aspnetcore-8.0" -The environment is set using any of the following approaches: - * Blazor Server: Use any of the approaches described in for general ASP.NET Core apps. -* Blazor Server or Blazor WebAssembly: [Blazor start configuration](#set-the-client-side-environment-via-blazor-startup-configuration) +* Blazor Server or Blazor WebAssembly: + * [Blazor start configuration](#set-the-client-side-environment-via-blazor-startup-configuration) + * [Azure App Service](#set-the-environment-for-azure-app-service) * Blazor WebAssembly: [`Blazor-Environment` header](#set-the-client-side-environment-via-header) -* Blazor Server or Blazor WebAssembly: [Azure App Service](#set-the-environment-for-azure-app-service) - -On the client for a Blazor Web App or the client of a hosted Blazor WebAssembly app, the environment is determined from the server via a middleware that communicates the environment to the browser via a header named `Blazor-Environment`. The header sets the environment when the is created in the client-side `Program` file (). -:::moniker-end +On the client of a hosted Blazor WebAssembly app, the environment is determined from the server via a middleware that communicates the environment to the browser via a header named `Blazor-Environment`. The header sets the environment when the is created in the client-side `Program` file (). For a standalone Blazor WebAssembly app running locally, the development server adds the `Blazor-Environment` header with the environment name obtained from the hosting environment. The hosting environment sets the environment from the `ASPNETCORE_ENVIRONMENT` environment variable established by the project's `Properties/launchSettings.json` file. The default value of the environment variable in a project created from the Blazor WebAssembly project template is `Development`. For more information, see the [Set the client-side environment via header](#set-the-client-side-environment-via-header) section. +:::moniker-end + For app's running locally in development, the app defaults to the `Development` environment. Publishing the app defaults the environment to `Production`. :::moniker range="< aspnetcore-5.0" @@ -111,10 +135,14 @@ Standalone Blazor WebAssembly: **In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see . +:::moniker range="< aspnetcore-10.0" + Using the `environment` property overrides the environment set by the [`Blazor-Environment` header](#set-the-client-side-environment-via-header). The preceding approach sets the client's environment without changing the `Blazor-Environment` header's value, nor does it change the server project's console logging of the startup environment for a Blazor Web App that has adopted global Interactive WebAssembly rendering. +:::moniker-end + To log the environment to the console in either a standalone Blazor WebAssembly app or the `.Client` project of a Blazor Web App, place the following C# code in the `Program` file after the is created with and before the line that builds and runs the project (`await builder.Build().RunAsync();`): ```csharp @@ -124,6 +152,8 @@ Console.WriteLine( For more information on Blazor startup, see . +:::moniker range="< aspnetcore-10.0" + ## Set the client-side environment via header Blazor WebAssembly apps can set the environment with the `Blazor-Environment` header. Specifically, the response header must be set on the `_framework/blazor.boot.json` file, but there's no harm setting the header on file server responses for other Blazor file requests or the entire Blazor deployment. @@ -191,7 +221,7 @@ For more information: * [Apache documentation (search the latest release for "`mod_headers`")](https://httpd.apache.org/docs/) * [Blazor WebAssembly Apache hosting guidance](xref:blazor/host-and-deploy/webassembly#apache) -## Set the environment for Azure App Service +### Set the environment for Azure App Service