Skip to content

Cover matching BWA server and client project environments #36112

@guardrex

Description

@guardrex

Description

We're going to strip some info on this subject from the Prerendering article and probably add it back to the Environments article after the two open PRs merge.

Here's the original content (for .NET 8 or later) ...

The preceding example can demonstrate that it's possible to have a different server environment than client environment, which isn't recommended and may lead to arbitrary results. When setting the environment in a Blazor Web App, it's best to match server and `.Client` project environments. Consider the following scenario in a test app:

* Implement the client-side (`webassembly`) environment property with the `Staging` environment via `Blazor.start`. See the [Set the client-side environment via startup configuration](xref:blazor/fundamentals/environments#set-the-client-side-environment-via-blazor-startup-configuration) section of the *Environments* article for an example.
* Don't change the server-side `Properties/launchSettings.json` file. Leave the `environmentVariables` section with the `ASPNETCORE_ENVIRONMENT` environment variable set to `Development`.

You can see the value of the <xref:Microsoft.AspNetCore.Components.WebAssembly.Hosting.IWebAssemblyHostEnvironment.Environment?displayProperty=nameWithType> property change in the UI.

When prerendering occurs on the server, the component is rendered in the `Development` environment:

**:::no-loc text="Environment:":::** :::no-loc text="Development":::
When the component is rerendered just a second or two later, after the Blazor bundle is downloaded and the .NET WebAssembly runtime activates, the value changes to reflect that the client is operating in the `Staging` environment on the client:

**:::no-loc text="Environment:":::** :::no-loc text="Staging":::

The preceding example demonstrates why we recommend setting the server environment to match the client environment for development, testing, and production deployments.

Page URL

https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/environments?view=aspnetcore-9.0

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/fundamentals/environments.md

Document ID

8a5b47e7-b29c-b049-30e8-5b405a5086b6

Platform Id

42fc98f3-2606-72b5-f1b6-85add26a8204

Article author

@guardrex

Metadata

  • ID: cb8bc6ab-a440-d860-e40c-8f18aa1eafb3
  • PlatformId: 42fc98f3-2606-72b5-f1b6-85add26a8204
  • Service: aspnet-core
  • Sub-service: blazor

Related Issues

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions