Reputation: 3819
I am using Single Page Application with .Net core 2.2. I have following in my 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" });
});
But having following
public class CatchAllController : Controller
{
public IActionResult Index()
{
return File("~/index.html", "text/html");
}
}
gives me following error.
No file provider has been configured to process the supplied file
I was following following article (one difference. article uses API project. I had taken angular project).
https://www.richard-banks.org/2018/11/securing-vue-with-identityserver-part1.html
Upvotes: 3
Views: 4415
Reputation: 18175
I was just fighting this exact problem. Even though the File()
method claims to take a "virtual path" I could never get it to load the file without the error you're getting. Here's what I ended up piecing together after reading a number of different posts.
[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");
}
}
Upvotes: 3