Skip to content

Allow Environment variable to be more flexible in Blazor WebAssembly  #20935

@jernejk

Description

@jernejk

Is your feature request related to a problem? Please describe.

I'm currently trying to implement appsettings.*.json support.

I found this doc but not much else.
https://github.com/dotnet/AspNetCore.Docs/blob/1584f405e564a1d2ee974c128aac9bdfe5642949/aspnetcore/blazor/hosting-model-configuration.md

I was able to figure out how loading appsettings.json works and how appsettings.[env].json is decided and selected through reverse engineering but I couldn't figure out how would that work for GitHub pages or Azure Blob Storage Websites.

I found, that the header Blazor-Environment is how we control the environment and the header is determined by downloading https://localhost:5001/_framework/blazor.boost.json.

image

image
The code that seems to decide the environment is in case 1.

There is a workaround for GitHub pages to add HTTP Headers but it won't be picked up by Blazor js script because it only works for index.html.

<meta http-equiv="Blazor-Environment" content="Staging" />

Right now I'm writing a blog post on how to by-pass this problem by determining the environment via the current link and load correct app settings rather than use HTTP Header.

Describe the solution you'd like

Can we have a way to control what the environment is?
Can we override the environment in index.html, which can be modified at deployment?

Additional context

I'm using Blazor 3.2-Preview4 with Visual Studio 2019 16.6-Preview3.

Don't get me wrong, love the new feature and I just finished a blog post on how to make appsettings.json work similar as before in Preview3 only for Preview4 making it no longer the best solution. :) (although it still works, making appsettings embedded and update variables in build pipeline rather deployment pipeline)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssemblygood first issueGood for newcomers.help wantedUp for grabs. We would accept a PR to help resolve this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions