【问题标题】:No file provider has been configured to process the supplied file没有配置文件提供程序来处理提供的文件
【发布时间】:2023-04-01 20:10:01
【问题描述】:

我正在使用带有 .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 项目。我采用了 Angular 项目)。

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

【问题讨论】:

  • 您的项目是否启用了静态文件?
  • 我的 startp.cs => app.UseStaticFiles(); 中有这 2 个app.UseSpaStaticFiles();

标签: .net-core asp.net-core-mvc asp.net-core-2.0 asp.net-core-2.1


【解决方案1】:

我只是在解决这个确切的问题。即使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");
    }
}

【讨论】:

    猜你喜欢
    • 2019-08-27
    • 2010-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-08
    • 2014-08-07
    • 1970-01-01
    相关资源
    最近更新 更多