【发布时间】:2017-04-13 12:02:09
【问题描述】:
在我的 ASP.NET Core 项目中,我尝试提供这样的 html 文件:
public IActionResult Index()
{
return File("c:/path/to/index.html", "text/html");
}
这会导致错误:
FileNotFoundException: Could not find file: c:/path/to/index.html
将 ErrorMessage 中的路径粘贴到我的浏览器中,我可以打开该文件,因此该文件显然存在。
我能够提供该文件的唯一方法是将其放在项目文件夹中的 wwwroot 中并像这样提供它:
public IActionResult Index()
{
return File("index.html", "text/html");
}
我已经更改了使用 app.UseStaticFiles(options) 提供静态文件的文件夹(有效),所以我认为控制器会默认使用该文件夹,但它一直在 wwwroot 中查找。
如何从控制器提供位于 wwwroot 之外甚至项目之外的文件?
【问题讨论】:
-
在此处查看我对另一个类似问题的回答stackoverflow.com/questions/43256864/…
标签: c# asp.net-core asp.net-core-mvc