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

How to access Azure Linux web app path file

正在尝试访问路径上的文件 - wwwroot/templates/file.txt。它在 windows 上使用 -_hostingEnvironment.ContentRootPath + "\templates\file.txt" 但相同的路径表示文件不存在。 我错过了什么

Trying to access file on path - 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();

并且请确保该文件确实存在于您服务器上的该文件夹下。

测试结果