在发布模式下发布后,带有 net5.0(托管)的 Blazorwasm 会抛出 404 和 Fallback {*path:nonfile}

时间:2020-12-18 18:10:45

标签: c# blazor blazor-webassembly .net-5

我在尝试使用 net5 部署全新的 blazorwasm 时遇到问题。 这是我一直遵循的步骤。 创建一个新项目。

dotnet new blazorwasm -f net5.0 --hosted --auth none

导航到服务器目录并发布:

dotnet publish -c Release

然后启动服务器:

dotnet /project/Server/bin/Release/net5.0/publish/project.Server.dll

然后我可以看到服务器正在运行,但是当我尝试访问 url https://localhost:5001 时,我得到了 404。所以我想知道我是做错了什么还是这个 blazorwasm 有问题模板。

enter image description here

环境信息:

dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.101
 Commit:    d05174dc5a

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.15
 OS Platform: Darwin
 RID:         osx.10.15-x64
 Base Path:   /usr/local/share/dotnet/sdk/5.0.101/

Host (useful for support):
  Version: 5.0.1
  Commit:  b02e13abab

.NET SDKs installed:
  1.0.0-preview2-003156 [/usr/local/share/dotnet/sdk]
  1.0.0-preview2-1-003177 [/usr/local/share/dotnet/sdk]
  1.0.1 [/usr/local/share/dotnet/sdk]
  2.0.0 [/usr/local/share/dotnet/sdk]
  3.0.100 [/usr/local/share/dotnet/sdk]
  3.1.302 [/usr/local/share/dotnet/sdk]
  3.1.401 [/usr/local/share/dotnet/sdk]
  3.1.404 [/usr/local/share/dotnet/sdk]
  5.0.100 [/usr/local/share/dotnet/sdk]
  5.0.101 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.10 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 1.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 1.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 1.1.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 1.1.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.21 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.23 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.10 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

1 个答案:

答案 0 :(得分:0)

运行以下命令时查看“内容根目录”:dotnet /project/Server/bin/Release/net5.0/publish/project.Server.dll

内容根目录是您运行命令的地方,也是您网站的根目录。

在您的情况下,您从项目路径运行,该路径不是实际的内容根目录,因此预计会出现 404 错误。

如果您移动到发布文件夹:

cd D:\blazor\StackOverFlow\So1\Server\bin\Release\net5.0\publish

然后运行命令:

dotnet run project.Server.dll

现在,内容根路径是 /project/Server/bin/Release/net5.0/publish

解决办法:

运行下一批:

cd /project/Server/bin/Release/net5.0/publish
::launch firefox/chrom
start "" "https://localhost:5001"
dotnet project.Server.dll

首页显示正常,无 404 错误。