在本地機器上,下面的代碼正常工作,但是當託管在遠程服務器上時,它似乎沒有找到圖像文件。我創建了圖像文件夾並賦予它讀取/寫入權限在ASP.NET MVC 3.0中上傳圖像時出現錯誤
// ------------------------------ --------------
錯誤
Server Error in '/' Application.
Could not find file 'IdImage.jpg'.
描述:在當前web請求的執行過程中發生了未處理的異常。請查看堆棧跟蹤以獲取有關該錯誤的更多信息以及源代碼的位置。
Exception Details: System.IO.FileNotFoundException: Could not find file 'IdImage.jpg'.
代碼是如下
// --------------------------------- ------------
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/Images/Photo"), fileName);
file.SaveAs(path);
}
return RedirectToAction("Index");
}