[Blazor web assembly] On page reload for a deployed app, set environment (environment's appsettings file) not being picked
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Describe the bug
Following the setup of multiple environments via startup configuration as specified here in this documentation - https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/environments?view=aspnetcore-7.0#set-the-environment-via-startup-configuration Below is the configuration set in the index.html file
<script>
document.addEventListener("DOMContentLoaded", function () {
if (window.location.hostname.includes("localhost")) {
Blazor.start(); //ensures that @localhost, the default debugging flow can be used.
} else if (window.location.hostname.includes("test")) {
Blazor.start({
environment: "Test"
});
} else if (window.location.hostname.includes("demo")) {
Blazor.start({
environment: "Demo"
});
} else {
Blazor.start({
environment: "Production"
});
}
});
</script>
A standalone wasm app deployed to use an environment like demo works well upon visiting the root domain eg https://example-demo.com. If one navigates to a page like https://example-demo.com/votes, votes page will load as expected. Issue arises when you reload the page. Blazor seems to default to using appsetting.Production.json instead of reloading using appsettings.Demo.json Strangely this works well for test. NB: Deployment is being done by deploying the published assets to object storage or a similar approach to GitHub pages
Expected Behavior
If on the votes page - https://example-demo.com/votes and you reload, blazor is supposed to use the appsettings.Demo.json
Steps To Reproduce
Have in place appsettings for development, test, demo, production. Add a the code snippet above mentioned in the describe bug section to your index.html file. while executing dotnet publish command, specify environment name accordingly using /p:EnvironmentName
Exceptions (if any)
No response
.NET Version
.NET 7
Anything else?
No response
Issue Analytics
- State:
- Created 5 months ago
- Reactions:1
- Comments:13 (9 by maintainers)
@javiercn @mkArtakMSFT blazor.boot.json throws no error logs. The only error logs are CORS errors since wrong Base URLs are loaded and these API URLs are defined in appsettings for different environments. Below is a screenshot of the network tab in developer tools:
NB: BTW Our experiments with docker as a deployment option have this working well.
Sounds good. Closing as there is not enough information for us to investigate this further. Glad that you have found a solution anyway.