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 应用程序


基础教程推荐
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01