简体   繁体   中英

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

I have a program in asp.Net MVC. My server is 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'

What is wrong with my code? Should I use something different when using plesk?

OK then, most likely it is because your IIS user does not have write permission to write on that folder. Add full permission on the folder. The user must be something like: Plesk IIS WP User .

You can simply allow write/modify permission for subscription in Hosting Settings:

ASP .NET Plesk权限文件

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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