【问题标题】:How to access Azure Linux web app path file如何访问 Azure Linux Web 应用程序路径文件
【发布时间】:2020-06-28 12:38:49
【问题描述】:

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

【问题讨论】:

    标签: linux file asp.net-core azure-webapps


    【解决方案1】:

    尝试访问路径上的文件 - wwwroot/templates/file.txt。

    下面的代码sn -p对我有用,你可以参考一下。

    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();
    

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

    测试结果

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-09
      • 2023-01-29
      • 2011-01-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多