.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
相关产品推荐
相关产品推荐

