Hi Abp Team,
I am having trouble configuring the URL for the Blazor UI for Docker container after publishing. The situation is that after publishing, the container only works with the AppSelfUrl that was used while creating the project image. So, I tried the solution suggested in placing UseStaticFiles() before AbpMapStaticAssets(), but it did not solve the issue. I also tried adding BlazorEnableCompression to Blazor.Client.csproj to disable compression, but it also did not help. I used methods like UseStaticFilesForPatterns("appsettings*.json") and UseStaticFiles() with and without AbpMapStaticAssets().
What I want is to be able to change the configuration of the Blazor project after publishing. The project consists of multiple modules.
5 Answer(s)
-
0
To change the configuration (such as API URLs) of an ABP Blazor WebAssembly application after publishing—especially in a Docker or cloud environment—you should use environment-specific configuration files that can be overridden at runtime.
Key Solution Steps:
Use environment-specific JSON files:
- Place
appsettings.{ENVIRONMENT}.json
(e.g.,appsettings.Production.json
) in thewwwroot
folder of your Blazor WASM project. - At runtime, the Blazor app will fetch the appropriate configuration file based on the environment.
- Place
Override configuration at runtime:
- In Docker or Kubernetes, mount a volume or use a ConfigMap/Secret to provide the correct
appsettings.{ENVIRONMENT}.json
file at container startup. - This allows you to change URLs and other settings without rebuilding the image.
- In Docker or Kubernetes, mount a volume or use a ConfigMap/Secret to provide the correct
Static file serving order:
- Ensure
app.UseStaticFiles()
is called beforeapp.MapAbpStaticAssets()
in your host project’sProgram.cs
orStartup.cs
. - Example:
- Ensure
app.UseStaticFiles(); app.MapAbpStaticAssets();
- Disable Blazor compression if needed:
- If you need to disable compression for easier file replacement, add the following to your
.csproj
:
- If you need to disable compression for easier file replacement, add the following to your
<BlazorEnableCompression>false</BlazorEnableCompression>
- This ensures files like
appsettings.json
are not compressed and can be replaced or read as plain text.
- UseStaticFilesForPatterns:
- If you want to serve only specific files, you can use:
app.UseStaticFilesForPatterns("appsettings*.json");
- Reload configuration:
- Blazor WASM reads configuration at startup. If you replace the config file, you must reload the app in the browser to pick up changes.
Summary:
For Dockerized or cloud deployments, provide the correctappsettings.{ENVIRONMENT}.json
at runtime via volume mounts or similar mechanisms. Ensure static files are served correctly and compression is disabled if you need to override files after publishing.Sources:
- Deployment microservices solution in K8S public cloud
- ABP Documentation: Configuration
- ABP Documentation: Blazor WASM Deployment
This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.
-
0
It did not solve the problem.
-
0
hi
Please share your startup module code?
The correct middleware code/order should be:
app.UseRouting(); var configuration = context.GetConfiguration(); if (Convert.ToBoolean(configuration["AuthServer:IsOnK8s"])) { app.Use(async (context, next) => { if (context.Request.Path.Value != null && context.Request.Path.Value.StartsWith("/appsettings", StringComparison.OrdinalIgnoreCase) && context.Request.Path.Value.EndsWith(".json", StringComparison.OrdinalIgnoreCase)) { // Set endpoint to null so the static files middleware will handle the request. context.SetEndpoint(null); } await next(context); }); app.UseStaticFilesForPatterns("appsettings*.json"); } app.MapAbpStaticAssets();
Thanks.
-
0
hi, I tried you suggestion but without if.It still did not worked.
Below is Blazor Module ▼
public override void OnApplicationInitialization(ApplicationInitializationContext context) { var env = context.GetEnvironment(); var app = context.GetApplicationBuilder(); // Configure the HTTP request pipeline. if (env.IsDevelopment()) { app.UseWebAssemblyDebugging(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseRouting(); app.Use(async (context, next) => { if (context.Request.Path.Value != null && context.Request.Path.Value.StartsWith("/appsettings", StringComparison.OrdinalIgnoreCase) && context.Request.Path.Value.EndsWith(".json", StringComparison.OrdinalIgnoreCase)) { // Set endpoint to null so the static files middleware will handle the request. context.SetEndpoint(null); } await next(context); }); app.UseStaticFilesForPatterns("appsettings*.json"); app.MapAbpStaticAssets(); app.UseAntiforgery(); app.UseConfiguredEndpoints(builder => { builder.MapRazorComponents<App>() .AddInteractiveWebAssemblyRenderMode() .AddAdditionalAssemblies(WebAppAdditionalAssembliesHelper.GetAssemblies<BillingBlazorClientModule>()); }); }
-
0
hi
Can you output some logs when
context.SetEndpoint(null);
? Make sure theEndpoint
isnull
for appsettings.json request.// Set endpoint to null so the static files middleware will handle the request. context.SetEndpoint(null);
Or can you try that?
public override void OnApplicationInitialization(ApplicationInitializationContext context) { var env = context.GetEnvironment(); var app = context.GetApplicationBuilder(); // Configure the HTTP request pipeline. if (env.IsDevelopment()) { app.UseWebAssemblyDebugging(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAntiforgery(); app.UseConfiguredEndpoints(builder => { builder.MapRazorComponents<App>() .AddInteractiveWebAssemblyRenderMode() .AddAdditionalAssemblies(WebAppAdditionalAssembliesHelper.GetAssemblies<BillingBlazorClientModule>()); }); }
Thanks.