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 应用程序
基础教程推荐
- WPF 模态进度窗口 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
