c# - "Could not find a part of the path"Azure应用程序中文件读取操作错误

标签 c# azure azure-web-app-service asp.net-core-1.1 azure-app-api

我构建了一个 ASP.NET Core api 应用程序,并将其部署到 Azure Web api 应用程序。 在代码中,我尝试在某个时刻读取内容根目录中文件的内容,并为其实际值插入某些占位符。

现在在我的本地系统上,这工作得很好,因为它能够获取文件的确切文件路径,但在云中,我收到一个异常,并显示以下消息:

Could not find a part of the path...

我得到完整的文件路径,如下所示:

Path.Combine(hostingEnvironment.ContentRootPath, "containing directory\filename")

但这在云中失败了。关于部署这个,我是否应该了解额外的信息,或者在理解云部署中的目录结构方面我做错了什么?

注意 我可以将此文件存储在 Azure 文件存储容器中,但我觉得读取它会很麻烦,而且会经常读取此文件,而且成本较高。

最佳答案

Could not find a part of the path...

根据异常,说明Azure中没有相关路径。如果可能的话,我们可以remote debug Azure Web Apps 。然后我们就可以得到文件路径了。之后我们可以使用Azure kudu(https://yoursite.scm.azurewebsites.net)工具来检查该路径是否存在。

enter image description here

如果文件路径不存在,我们可以直接将文件夹拖到kudu工具中,也可以使用Visual Studio发布该文件夹。之后它应该可以工作。

enter image description here

我们可以获得有关 Azure Web App sandbox 的更多信息。关于Azure网站文件结构请引用document

/
    LogFiles
        Application
            <instance>-<pid>-<ticks>.txt // application (nodejs/dotnet/php) traces
        DetailedError
            ErrorPage####.htm // error details
        Git
            trace
                trace.xml // Trace generated during git deployments
                <instance>-<guid>.txt // kudu related traces
            deployment
                <instance>-<guid>.txt // deployment related traces
        http
            RawLogs
                <logfile>.log     // iis http log. iis buffers and flushes every 60sec.
        W3SVC#####
            fr####.xml            // IIS fail request traces
            freb.xsl
    site
        wwwroot
            hello.htm             // The files that are live in your app
        repository                // Your repo, including working files (i.e. not bare)
            .git
                HEAD, index and other git files
        deployments
            [commit id 1]
                log.xml           // The deployment log, similar to what the protal shows
                status.xml        // The status of the deployment (success/failure)
                manifest          // The list of files that were deployed
            [commit id 2]
                ...
    .ssh
        config                // This contains config to disable strict host checking
        id_rsa                // private key in PEM format
        known_hosts           // known hosts have been accepted
    Data
        Jobs
            Triggered
                MyTriggeredJob1
                    20131112101559
                        output.log
                        error.log
                        status

            Continuous
                MyContinuousJob1
                    job.log
                    status
    SiteExtensions
        // TODO: add details here

关于c# - "Could not find a part of the path"Azure应用程序中文件读取操作错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45695304/

相关文章:

C#:填充 DataGridView 字段的宽度并在需要时添加滚动条

c# - 未处理的异常。系统聚合异常 : Some services are not able to be constructed

azure - 如何保护来自 WWW 的 Azure 网站/功能?

c# - 在 C# 中使用 HttpCookie 而不是 Session

c# - 在另一种形式上捕获图像,如何使用位图保持 dpi

wcf - Windows Phone 7.1 (Mango) 上的 NetTcpBinding

azure - 当前 session /用户的访问 token

c# - Azure 应用程序服务 Windows 容器 - 使用安装存储将文件上传到文件共享错误

c# - 使用 Reactive Extensions 同时处理流时如何限制缓冲

azure - 输出多个 CSV 文件,并通过 Azure 数据工厂使用映射数据流转换数据,合并为一个而不影响性能