gpt4 book ai didi

.net-core - 没有配置文件提供程序来处理提供的文件

转载 作者:行者123 更新时间:2023-12-04 02:29:33 25 4
gpt4 key购买 nike

我在 .Net core 2.2 中使用单页应用程序。我的 startup.cs 中有以下内容。

app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action=Index}/{id?}");

routes.MapSpaFallbackRoute(
name: "spa - fallback",
defaults: new { controller = "CatchAll", action = "Index" });

});

但有以下

public class CatchAllController : Controller
{
public IActionResult Index()
{
return File("~/index.html", "text/html");
}
}

给我以下错误。

没有配置文件提供程序来处理提供的文件

我正在关注以下文章(一个区别。文章使用 API 项目。我采用了角度项目)。

https://www.richard-banks.org/2018/11/securing-vue-with-identityserver-part1.html

最佳答案

我只是在解决这个确切的问题。即使 File() 方法声称采用“虚拟路径”,我也永远无法让它在没有出现错误的情况下加载文件。这是我在阅读了许多不同的帖子后最终拼凑起来的。

[Route("[controller]")]
public class DocumentationController : ControllerBase
{
private readonly IHostingEnvironment _env;

public DocumentationController(IHostingEnvironment env)
{
_env = env;
}

[HttpGet, Route("apiReference")]
public IActionResult ApiReference()
{
var filePath = Path.Combine(_env.ContentRootPath,
"Controllers/Documentation/My Document.pdf");
return PhysicalFile(filePath, "application/pdf");
}
}

关于.net-core - 没有配置文件提供程序来处理提供的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54615930/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com