【问题标题】:Azure, App service, "The system cannot find the file specified"Azure,应用服务,“系统找不到指定的文件”
【发布时间】:2017-02-27 14:11:22
【问题描述】:

在 Azure 应用服务中拥有一个应用。一个 .NET 网络项目。

跑线:

System.IO.File.ReadAllText("D:\home\site\wwwroot\Prod-Enterprise-Test-6-26-2016-credentials.publishsettings")

会抛出异常

系统找不到指定的文件。

您可以看到该文件在那里,相信我它没有拼写错误,在本地它可以正常工作,但在部署时会失败。

【问题讨论】:

    标签: azure azure-web-app-service


    【解决方案1】:

    你提到的代码需要修改如下:

    System.IO.File.ReadAllText(@"D:\home\site\wwwroot\Prod-Enterprise-Test-6-26-2016-credentials.publishsettings")
    

    你提到会抛出未找到的异常,这很奇怪。如果文件存在,代码应该可以在 azure 网站上运行。

    系统找不到指定的文件。

    似乎期望是由其他代码引起的。我们也可以remote debug the WebApp with Vistual Studio 获取有关异常的更多详细信息。

    我们还可以添加一个示例测试 aspx 页面来测试它。以下是我的测试步骤。

    1.创建一个.net Web项目和index.aspx页面

    2.将代码添加到index.aspx.CS文件和index.aspx文件中

     protected void Page_Load(object sender, EventArgs e)
            {
              var file= System.IO.File.ReadAllText(@"D:\home\site\wwwroot\Prod-Enterprise-Test-6-26-2016-credentials.publishsettings");
                Label1.Text = file;
            } 
    

    index.aspx

        <div>
    
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    
        </div>
    

    3.将网站发布到天蓝色环境并通过Kudu工具添加内容为“测试信息”的设置文件

    1. 从浏览器访问索引页面并检查它是否正常工作。

    【讨论】:

    • 这没有帮助
    • 你有没有尝试远程调试WebApp?
    • 我无法远程调试,它是 Azure sdk 的 2.2 版,并且存在一些错误。我可以写日志。
    • 如果可能,请尝试使用最新的Azure SDK
    【解决方案2】:

    嗯,问题出在代码中的不同位置。 发布的代码运行良好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多