You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mud Blazor应用设置基础路径后资源加载失败,求排查配置问题

Mud Blazor应用设置基础路径后资源加载失败,求排查配置问题

我创建了一个非常简单的Mud Blazor应用,但不知道为什么基础路径没有生效。这是我的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();

当我运行应用时,访问https://localhost:44381/是正常的,但我期望的是通过https://localhost:44381/foo/bar访问。然而当我访问这个地址时,CSS、mudblazor.min.js等资源都加载失败了。

我到底哪里配置错了?

资源加载失败截图

备注:内容来源于stack exchange,提问作者Dr Schizo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 10:50:34