Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core PhysicalFileProvider在asp.net控制器中应该如何工作 请考虑以下(部分)IApplicationBuilder和IWebHu宿环境配置: app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "WebContent")), RequestPath = "/WebContent" });_Asp.net Core_.net 5_Kestrel Http Server - Fatal编程技术网

Asp.net core PhysicalFileProvider在asp.net控制器中应该如何工作 请考虑以下(部分)IApplicationBuilder和IWebHu宿环境配置: app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "WebContent")), RequestPath = "/WebContent" });

Asp.net core PhysicalFileProvider在asp.net控制器中应该如何工作 请考虑以下(部分)IApplicationBuilder和IWebHu宿环境配置: app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "WebContent")), RequestPath = "/WebContent" });,asp.net-core,.net-5,kestrel-http-server,Asp.net Core,.net 5,Kestrel Http Server,在我的控制器中,我正在测试3种不同的方法: return LocalRedirect("~/WebContent/index.html"); 这是可行的,但我正在努力解决接下来的两个问题,不知道它们为什么会失败: return PhysicalFile("~/WebContent/index.html", "text/html"); 抛出:FileNotFoundException:找不到文件“C:\ProjectPath>\bin

在我的控制器中,我正在测试3种不同的方法:

return LocalRedirect("~/WebContent/index.html");
这是可行的,但我正在努力解决接下来的两个问题,不知道它们为什么会失败:

return PhysicalFile("~/WebContent/index.html", "text/html");
抛出:FileNotFoundException:找不到文件“C:\ProjectPath>\bin\Debug\net5.0~\WebContent\index.html”

return File("~/WebContent/index.html", "text/html");
抛出:FileNotFoundException:找不到文件:~/WebContent/index.html

如何访问/服务后两者的静态文件

我正在迭代输入的各种变化,所以需要一点背景知识


谢谢

您可以尝试以下代码:

    private readonly IWebHostEnvironment _hostingEnvironment;

    public HomeController(IWebHostEnvironment hostingEnvironment)
    {
        _hostingEnvironment = hostingEnvironment;
    }

    public IActionResult Index()
    {
       var path = Path.Combine(_hostingEnvironment.ContentRootPath, "WebContent/index.html");
       return PhysicalFile(path, "text/html");
    }

嗨@noontz,有关于这个案子的最新消息吗?没有。。。我还在挣扎。。我已经尝试过你的解决方案,但在我遇到的情况下它不起作用。。我的问题可能应该更具体一些。。如果我使用“WebContent\\index.html”,我将支持此操作。。其他一些因素阻碍了它在我的上下文中的使用,我本想得到一个关于File和PhysicalFile之间区别的解释,但我会把它标记为答案;)我看到了一个可能有用的链接,谢谢:)谢谢你的链接。。我想知道为什么在阅读了链接文章后,我的案例中的文件不起作用。。