当我尝试使用以下方法创建文件时,出现System.UnauthorizedAccessException错误:
using (var fileStream = System.IO.File.Create(filePath))
这是我得到的唯一的追踪信息。
Exception thrown: 'System.UnauthorizedAccessException' in System.Private.CoreLib.dll
这是在Docker上运行的ASP.NET Core 6 Web API。有什么想法吗?谢谢 :)
编辑: 这是我完整的代码片段,但它无法正常运行:
var filePath = Path.Combine(_environment.WebRootPath, "Uploads");
if(!Directory.Exists(filePath))
Directory.CreateDirectory(filePath);
using (var fileStream = System.IO.File.Create(filePath))
await file.CopyToAsync(fileStream);