1

我構建了一個ASP.NET Core api應用程序,並將其部署到Azure Web api應用程序。 在代碼中,我嘗試在某些時候讀取內容根目錄中的文件內容,將某些佔位符插入到其實際值中。「無法找到路徑的一部分」Azure應用中的文件讀取操作錯誤

現在我的本地系統上這工作得很好因爲它是能夠得到文件的確切文件路徑,但在雲中,我得到以下消息的異常:

找不到路徑的一部分......

我得到完整的文件路徑,像這樣:

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

但這未能在雲中。我是否應該瞭解有關部署此內容的額外信息,或者我在理解雲部署中的目錄結構方面做了什麼錯誤?

N.B 我可以將此文件存儲在Azure文件存儲容器中,但是我覺得閱讀起來會很麻煩,而且看到這個文件會被頻繁地讀取。

回答

1

找不到路徑的一部分...

根據該例外,它表明有在Azure中沒有相關的路徑。如果可能的話,我們可以remote debug Azure Web Apps。然後我們可以得到文件路徑。之後,我們可以使用Azure kudu(https://yoursite.scm.azurewebsites.net)工具來檢查路徑是否存在。

enter image description here

如果文件路徑是不存在的,我們可以拖動文件夾直接捻工具,或者我們也可以發佈與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 
+0

非常詳細的解答,幫助突出,並填寫我的知識基礎等諸多漏洞。我訴諸Azure文件共享,但實施一些在這裏建議的事情幫助實現了我想要的十億! –

相關問題