简体   繁体   English

使用plesk时如何根据相对或虚拟路径保存文件?

[英]How to save file based on relative or virtual path when using plesk?

I have a program in asp.Net MVC. 我在asp.Net MVC中有一个程序。 My server is plesk. 我的服务器是plesk。

I save my files using this method: 我使用这种方法保存我的文件:

public string SaveFile(HttpPostedFileBase file, string path)
{
    string fileName = Guid.NewGuid() + file.FileName;
    var filePath = Path.Combine(Server.MapPath("~/Images/"), fileName);
    file.SaveAs(filePath);
    return fileName;
}

and file saving is OK in test computer. 测试计算机中的文件保存正常。 But after uploading on server I get this error: 但在服务器上传后我收到此错误:

Could not find a part of the path 'C:\\Inetpub\\vhosts\\hostname.com\\mysitename.com\\Images\\myFile.jpg' 找不到路径'C:\\ Inetpub \\ vhosts \\ hostname.com \\ mysitename.com \\ Images \\ myFile.jpg'的一部分

What is wrong with my code? 我的代码出了什么问题? Should I use something different when using plesk? 使用plesk时我应该使用不同的东西吗?

OK then, most likely it is because your IIS user does not have write permission to write on that folder. 那么,很可能是因为您的IIS用户没有写入该文件夹的写入权限。 Add full permission on the folder. 添加该文件夹的完全权限。 The user must be something like: Plesk IIS WP User . 用户必须是: Plesk IIS WP User

You can simply allow write/modify permission for subscription in Hosting Settings: 您只需在主机设置中允许订阅的写入/修改权限:

ASP .NET Plesk权限文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM