找不到 Razor 应用程序 404 页面

Razor application 404 page not found

提问人:Anibal Yeh 提问时间:11/15/2023 更新时间:11/15/2023 访问量:44

问:

当我使用 .Net 5 Razor 启动应用程序时

dotnet BaGet.dll

它总是说找不到 404 页面。

enter image description here

但是,如果我 dotnet 运行它或执行 BaGet.exe 文件,一切都很好。

所有这些静态文件都分离在另一个项目中

enter image description here

https://github.com/loic-sharma/BaGet

var path = Path.Combine(_env.ContentRootPath, "..", "BaGet.Web");

ContentRootPath 是正确的

var provider = new PhysicalFileProvider(Path.GetFullPath(path))

是否经过验证?

如何正确使用“dotnet BaGet.dll”?

C# ASP.NET 核心 剃刀

评论

0赞 Jason Pan 11/16/2023
您能检查下面的解决方案吗?如果您需要进一步的帮助,请告诉我。
0赞 Anibal Yeh 11/17/2023
今天就让我来检查一下!!谢谢!我的一个信息,我正在使用 .net 5.0,这重要吗?
0赞 Jason Pan 11/17/2023
它与 .Net 版本无关。您可以检查 wwwroot 文件夹中是否有这些 js 和 css 文件。
0赞 Anibal Yeh 11/23/2023
在我尝试过这个之后,它对我不起作用。

答:

0赞 Jason Pan 11/15/2023 #1

这是预期行为。wwwroot 文件夹下没有任何静态文件

最后,我在这里找到了所有文件。

enter image description here

然后将它们复制到项目内的文件夹中,如下所示。wwwroot

enter image description here

并在 .csproj 文件中添加以下设置,其中将在生成项目时包含静态文件。

  <ItemGroup>
    <None Include="wwwroot\**">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>

然后我们将在 .wwwrootYOUR_DRIVER:\BaGet-main\BaGet-main\src\BaGet\bin\Debug\netcoreapp3.1

enter image description here

好了,现在您可以运行命令来启动项目了。

enter image description here

0赞 Anibal Yeh 11/23/2023 #2

静态网络资产

最终的答案是发布应用程序和 UseStaticFiles 有效。