Open Closed

Configure Blazor Wasm after publishing moduled project. #10010


User avatar
0
samirmustafayev created

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)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent

    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:

    1. Use environment-specific JSON files:

      • Place appsettings.{ENVIRONMENT}.json (e.g., appsettings.Production.json) in the wwwroot folder of your Blazor WASM project.
      • At runtime, the Blazor app will fetch the appropriate configuration file based on the environment.
    2. 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.
    3. Static file serving order:

      • Ensure app.UseStaticFiles() is called before app.MapAbpStaticAssets() in your host project’s Program.cs or Startup.cs.
      • Example:
    app.UseStaticFiles();
         app.MapAbpStaticAssets();
    
    1. Disable Blazor compression if needed:
      • If you need to disable compression for easier file replacement, add the following to your .csproj:
    <BlazorEnableCompression>false</BlazorEnableCompression>
    
    • This ensures files like appsettings.json are not compressed and can be replaced or read as plain text.
    1. UseStaticFilesForPatterns:
      • If you want to serve only specific files, you can use:
    app.UseStaticFilesForPatterns("appsettings*.json");
    
    1. 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 correct appsettings.{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:


    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.

  • User Avatar
    0
    samirmustafayev created

    It did not solve the problem.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    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.

  • User Avatar
    0
    samirmustafayev created

    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>());
        });
    }
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you output some logs when context.SetEndpoint(null);? Make sure the Endpoint is null 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.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.1.0-preview. Updated on October 17, 2025, 13:15