"Could not find a part of the path" Azure 应用程序中的文件读取操作错误
"Could not find a part of the path" Error For File Read Operation in Azure App
我构建了一个 ASP.NET 核心 api 应用程序,它被部署到 Azure web api 应用程序。
在代码中,我尝试在某些时候读取内容根目录中的文件内容,为它们的实际值插入某些占位符。
现在在我的本地系统上它工作得很好,因为它能够获取文件的确切文件路径,但在云中,我收到以下消息的异常:
Could not find a part of the path...
我得到完整的文件路径是这样的:
Path.Combine(hostingEnvironment.ContentRootPath, "containing directory\filename")
但这在云中失败了。关于部署这个我应该知道什么额外的东西,或者我在理解云部署中的目录结构方面做错了什么?
N.B
我可以将此文件存储在 Azure 文件存储容器中,但我觉得读取它会很麻烦,而且经常读取此文件的成本也很高。
Could not find a part of the path...
根据异常,说明Azure中没有相关路径。如果可能的话,我们可以remote debug Azure Web Apps. Then we could get the file path. After that we could use the Azure kudu(https://yoursite.scm.azurewebsites.net)工具来检查路径是否存在。
如果文件路径不存在,我们可以直接将文件夹拖到kudu工具,也可以用Visual Studio发布文件夹。之后它应该可以工作了。
我们可以获得更多关于 Azure Web App sandbox. About Azure website file structure please refer the 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
我构建了一个 ASP.NET 核心 api 应用程序,它被部署到 Azure web api 应用程序。 在代码中,我尝试在某些时候读取内容根目录中的文件内容,为它们的实际值插入某些占位符。
现在在我的本地系统上它工作得很好,因为它能够获取文件的确切文件路径,但在云中,我收到以下消息的异常:
Could not find a part of the path...
我得到完整的文件路径是这样的:
Path.Combine(hostingEnvironment.ContentRootPath, "containing directory\filename")
但这在云中失败了。关于部署这个我应该知道什么额外的东西,或者我在理解云部署中的目录结构方面做错了什么?
N.B 我可以将此文件存储在 Azure 文件存储容器中,但我觉得读取它会很麻烦,而且经常读取此文件的成本也很高。
Could not find a part of the path...
根据异常,说明Azure中没有相关路径。如果可能的话,我们可以remote debug Azure Web Apps. Then we could get the file path. After that we could use the Azure kudu(https://yoursite.scm.azurewebsites.net)工具来检查路径是否存在。
如果文件路径不存在,我们可以直接将文件夹拖到kudu工具,也可以用Visual Studio发布文件夹。之后它应该可以工作了。
我们可以获得更多关于 Azure Web App sandbox. About Azure website file structure please refer the 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