如何使用 MVC 以最小访问权限在服务器上记录文件
如何使用 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));
(如果可以通过将文件放入缓存来实现这一点)
编辑代码:
varordinaryPropertyValue = new Catalog.Core。 Entities.OrdinaryPropertyValue();
环境.CurrentDirectory = 环境.GetEnvironmentVariable("TEMP");
var fileFile = Request.Files["File" + prop.Id]; if (fileFile == null) 继续;
字符串路径文件=环境.当前目录;
文件文件.另存为(路径文件);
普通PropertyValue.Value = pathFile;
instance.SetPropertyValue(prop.Id,ordinaryPropertyValue);
How to record files on a server with minimal access using MVC. The next version of the code is not suitable as it will be clogging up the domain.
Controller code:
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));
(if it is possible to realize this by putting file to the cache)
EDITED CODE:
var ordinaryPropertyValue = new Catalog.Core.Entities.OrdinaryPropertyValue();
Environment.CurrentDirectory = Environment.GetEnvironmentVariable("TEMP");
var fileFile = Request.Files["File" + prop.Id];
if (fileFile == null) continue;
string pathFile = Environment.CurrentDirectory;
fileFile.SaveAs(pathFile);
ordinaryPropertyValue.Value = pathFile;
instance.SetPropertyValue(prop.Id, ordinaryPropertyValue);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用通用的应用程序数据位置(如果您需要保留它们,这将比 %TEMP% 更好 - 根据我的经验,人们倾向于不时清理 %TEMP% 文件夹) - 所有用户都应该有访问该文件夹,然后您可以将其放入子文件夹中,如下所示:
以下是所有“特殊文件夹”,以防您看到您更愿意使用的文件夹:Environment.SpecialFolder
You could use the common application data location (this would be better than %TEMP% if you need them to stick around - people have a tendency to clean the %TEMP% folder out from time to time in my experience) - all users should have access to that and then you could just put it in a sub-folder like so:
Here are all the "special folders" in case you see one that you would rather use: Environment.SpecialFolder