In my ASP.NET Core project I am trying to serve an html file like this:
public IActionResult Index()
{
return File("c:/path/to/index.html", "text/html");
}
This results in an Error:
FileNotFoundException: Could not find file: c:/path/to/index.html
Pasting the path from the ErrorMessage into my browser I am able to open the file, so the file is clearly there.
The only way I have been able to serve the file is placing it in wwwroot in the project folder and serving it like this:
public IActionResult Index()
{
return File("index.html", "text/html");
}
I have already changed the folder I serve static files from using app.UseStaticFiles(options)
(which works), so I figured the Controller would use that folder as default, but it keeps looking in wwwroot.
How can I serve a file that is placed outside of wwwroot, or even outside the project, from a Controller?