问题描述
我有一个在 Visual Studio 2017 中创建的 ASP.NET Web 应用程序.
I have an ASP.NET web application, created in Visual Studio 2017.
在应用程序中有一个表单,用户可以在其中上传文件.上传文件后,我会处理它们并将它们保存在文件系统中:
In the application there is a form, where the users can upload files. When files are uploaded, I process them and I save them on the filesystem:
var photo = Request.Files["file"];
photo.SaveAs("D:\home");
在本地一切正常,但是当我在 Azure 应用服务上部署应用程序时却无法正常工作.
Everything works perfect locally, but it's not working when I deploy the App on Azure App Services.
我在 Azure 上读到了路径
I read that, on Azure, the path
D:home
应该是可写的.
但是当我尝试代码时,我得到了这个错误:
But when I try the code I get this error:
Access to the path 'd:home est_image.JPG' is denied.
推荐答案
使用 %TEMP%
,在 Azure App Service (Windows) 上解析为 d:local
.那是本地机器磁盘,而不是网络存储,因此速度明显更快.它会在应用重启时被擦除,因此请相应地编写代码.
Use %TEMP%
, which on Azure App Service (Windows) resolves to d:local
. That's the local machine disk, not network storage, so significantly faster. It gets wiped on app restart so code accordingly.
var tempDirectoryPath = Environment.GetEnvironmentVariable("TEMP");
var filePath = Path.Combine(tempDirectoryPath, Request.Files["file"]);
如果您想要持久性,请改用 Blob 存储.
If you want durability use Blob Storage instead.
这篇关于Azure 应用服务 - 写入文件系统 - ASP.NET Web 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!