问题描述
在Azure上运行.net应用程序时遇到问题。使用CreateDirectory方法时,它将引发FileNotFoundException并显示消息找不到文件'D:\home\site\wwwroot\CVs'。。
I am facing a problem when running .net app on Azure. When using CreateDirectory method, it throws FileNotFoundException with the message of "Could not find file 'D:\home\site\wwwroot\CVs'.".
在本地和专用服务器上运行时,该应用程序正常运行。知道是什么问题吗?
The app worked without any exception when running locally and on a private server. Any idea what could be the problem?
Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "CVs"));
推荐答案
假设您正在以Azure Web App,由于要处理Azure Web Apps虚拟机的性质,因此需要小心尝试写入文件系统。
Assuming, that you're running your app as an Azure Web App, you need to be careful what you try to write to the file system, because of the nature of how the virtual machines of Azure Web Apps are handled.
由于Azure不能每次都保证同一台VM的可用性,而只能保证运行您的应用程序的VM的可用性,因此这意味着文件系统(除了您部署的应用程序文件之外)不能保证持久。如果您的应用是可扩展的,那么我们将输入一个新的多个VM之间的持久性问题。
Since Azure doesn't guarantee the availability of the same VM each time, but only the availability of a VM running your app, this means the file system (beyond the app files you deployed) isn't guaranteed to persist. If your app is scaled, then we're entering a whole new problem of persistence between multiple VMs.
请查看以下问题的答案以获取更多详细信息:
Check the answer to the following question for more details:https://stackoverflow.com/a/12968226/912268
这篇关于使用System.IO.Directory.CreateDirectory()时发生FileNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!