如何使用 MVC 在具有最小访问权限的服务器上记录文件。下一个版本的代码不适合,因为它会阻塞域。
控制器代码:
var fileFile = Request.Files["p" + prop.Id];
if (fileFile == null) continue;
string pathFile = AppDomain.CurrentDomain.BaseDirectory + "UploadedFiles";
string filenameFile = Path.GetFileName(fileFile.FileName);
if (filenameFile != null) fileFile.SaveAs(Path.Combine(pathFile, filenameFile));
(如果可以通过将文件放入缓存来实现这一点)
编辑代码:
var normalPropertyValue = new Catalog.Core.Entities.OrdinaryPropertyValue();
Environment.CurrentDirectory = Environment.GetEnvironmentVariable("TEMP");
var fileFile = Request.Files["File" + prop.Id]; if (fileFile == null) 继续;
字符串路径文件 = Environment.CurrentDirectory;
文件文件.另存为(路径文件);
普通属性值.值 = 路径文件;
instance.SetPropertyValue(prop.Id, normalPropertyValue);