如何访问Azure Linux web应用程序路径文件

如何访问Azure Linux web应用程序路径文件,linux,file,asp.net-core,azure-webapps,Linux,File,Asp.net Core,Azure Webapps,正在尝试访问路径为wwwroot/templates/file.txt的文件。它在windows上使用--u hostingEnvironment.ContentRootPath+“\templates\file.txt”工作,但同一路径表示文件不存在。 我错过了什么 正在尝试访问路径为wwwroot/templates/file.txt的文件 下面的代码片段对我很有用,您可以参考它 var filepath = Path.Combine(_hostingEnvironment.ContentR

正在尝试访问路径为wwwroot/templates/file.txt的文件。它在windows上使用--u hostingEnvironment.ContentRootPath+“\templates\file.txt”工作,但同一路径表示文件不存在。 我错过了什么

正在尝试访问路径为wwwroot/templates/file.txt的文件

下面的代码片段对我很有用,您可以参考它

var filepath = Path.Combine(_hostingEnvironment.ContentRootPath, "templates", "file.txt");

var mes = "test message";

if (System.IO.File.Exists(filepath))
{
    using (StreamReader file = new StreamReader(filepath))
    {
        mes = file.ReadLine();
    }
}

ViewBag.fp = filepath;

ViewBag.mes = mes;

return View();
请确保该文件确实存在于服务器上的该文件夹下

测试结果