Azure App Service - write to filesystem - ASP.NET web application(Azure 应用服务 - 写入文件系统 - ASP.NET Web 应用程序)
问题描述
我有一个在 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 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Azure 应用服务 - 写入文件系统 - ASP.NET Web 应用程序


- C# 中多线程网络服务器的模式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04