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

.NET 8 Blazor Web App修改Base URL后_blazor.web.js报404

.NET 8 Blazor Web App 修改Base URL后 _framework/blazor.web.js 404问题

我通过Visual Studio模板创建了包含服务端和客户端项目的.NET 8 Blazor Web App,需要将应用Base URL修改为/portals/sales,已完成以下修改:

  • 修改服务端Program.cs:
app.UseBlazorFrameworkFiles(new PathString("/portals/sales"));
app.UseStaticFiles("/portals/sales");
app.UseAntiforgery();

app.MapRazorComponents<App>()
    .AddInteractiveServerRenderMode()
    .AddInteractiveWebAssemblyRenderMode(options =>
        options.PathPrefix = "/portals/sales")
    .AddAdditionalAssemblies(typeof(MK.Sales.Portal.Client._Imports).Assembly);
  • 修改App.razor:
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <base href="/portals/sales/" />
    <link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
    <link rel="stylesheet" href="app.css" />
    <link rel="stylesheet" href="MK.Sales.Portal.styles.css" />
    <link rel="icon" type="image/png" href="favicon.png" />
    <HeadOutlet />
</head>

<body>
    <Routes />
    <script src="/portals/sales/_framework/blazor.web.js"></script>
</body>

</html>
  • 修改服务端项目文件(.csproj):
<PropertyGroup>
  <TargetFramework>net8.0</TargetFramework>
  <Nullable>enable</Nullable>
  <ImplicitUsings>enable</ImplicitUsings>
  <StaticWebAssetBasePath>/portals/sales/</StaticWebAssetBasePath>
</PropertyGroup>

当前问题:访问https://localhost:5001/portals/sales时,其他资源加载正常,但_framework/blazor.web.js返回404无法加载;手动访问https://localhost:5001/_framework/blazor.web.js则可正常加载。Blazor未从修改后的Base路径/portals/sales提供该文件,仍从根路径获取,不清楚遗漏了哪些配置。

更新内容

  • 更新1:已将示例项目上传至GitHub仓库
  • 更新2:经确认此为.NET官方Bug,已提交对应的GitHub Issue

内容的提问来源于stack exchange,提问作者kyurkchyan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 03:50:08