首页 > 解决方案 > 如何在 C# 中使用 ASP.NET Core 5 在每条路由上提供静态文件夹?

问题描述

现在我用

app.UseDefaultFiles();
app.UseStaticFiles();

UseWebRoot("./public");

/在路线上提供公用文件夹。

其中包含

index.html
bundle.js

如果我使用该/nested路由,它将nested在我的文件服务器中查找文件夹。

如果我在每条路线上使用app.UseSpa()app.UseSpaStaticFiles();使用,return File("index.html", "text/html");它将把公用文件夹中的每个文件作为index.html.

如何配置以便我可以在每条路由上为同一个公用文件夹提供默认文件?

例如,如果我要求/nested/route我仍想提供将在该文件夹public中呈现index.html的文件夹,而不是public/nested/route文件夹。

标签: asp.netasp.net-coreasp.net-web-apisingle-page-application

解决方案


推荐阅读