Dr Schizo
Dr Schizo

Reputation: 4366

How to set base path for a Mud Blazor App

I have created a very simple mud blazor app but for some odd reason the base path is not being respected. This is my program.cs

var builder = WebApplication.CreateBuilder(args);

// Add MudBlazor services
builder.Services.AddMudServices();

// Add services to the container.
builder.Services.AddRazorComponents()
    .AddInteractiveWebAssemblyComponents();

var app = builder.Build();
app.UsePathBase("/foo/bar");

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseWebAssemblyDebugging();
}
else
{
    app.UseExceptionHandler("/Error", createScopeForErrors: true);
    // 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.UseStaticFiles(new StaticFileOptions()
{
    RequestPath = "/foo/bar",
    ServeUnknownFileTypes = true,
});
app.UseAntiforgery();

app.MapRazorComponents<App>()
    .AddInteractiveWebAssemblyRenderMode()
    .AddAdditionalAssemblies(typeof(MudBlazorWebApp1.Client._Imports).Assembly);

app.Run();

When I run this, it works when I target the address https://localhost:44381/ but I am expecting to hit on https://localhost:44381/foo/bar but when I do this it fails to load up the assets like CSS and mublazor.min.js etc

What am I doing wrong here?

enter image description here

Upvotes: 0

Views: 54

Answers (1)

Ruikai Feng
Ruikai Feng

Reputation: 11896

set the base herf in your app.razor:

<base href="/foo/bar/" />

Now static files could be load properly: enter image description here

Upvotes: 2

Related Questions