2012-08-09 68 views
0

我在Mono + Apache2上運行ASP.NET時遇到了一個問題。 我把FileUpload控件的頁面,當點擊按鈕上傳文件時,它會拋出一個異常:單聲道文件上傳控制

找不到路徑的一部分「/var/www/www.mysite.com/upload /headImage/uid_1.jpg」。

描述:HTTP 500.錯誤處理請求。

堆棧跟蹤:

System.IO.DirectoryNotFoundException:找不到路徑 「/var/www/www.mysite.com/upload/headImage/uid_1.jpg」 的一部分。在System.Web.UI的System.Web.HttpPostedFile.SaveAs(System.String文件名)[0x00000]處:0 中的System.IO.File.Delete(System.String path)[0x00000]處的 處:0 。 WebControls.FileUpload.SaveAs(System.String文件名)[0x00000] in::0 at WebApplication.users.ImageUpload.btnUpload_Click(System.Object sender,> System.EventArgs e)[0x00000] in:0 at System.Web在System.Web.UI.WebControls.Button.RaisePostBackEvent(System.String eventArgument)中的.UI.WebControls.Button.OnClick(System.EventArgs e)[0x00000]中的:0 >:[0x00000]:0 。 Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent>(System.String eventArgument)[0x00000] in:0 at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,> Sys在System.Web.UI.Page.RaisePostBackEvents()[0x00000]中:0 在System.Web.UI.Page.ProcessRaiseEvents()[0x00000]中:0 在System.Web.UI.Page.InternalProcessRequest()[0x00000]在:0 在System.Web.UI.Page.ProcessRequest(System.Web.HttpContext上下文)[0x00000]在:0

我確定路徑「/var/www/www.mysite.com/upload/headImage/」存在並且已經是chmod 766,並且該文件夾中不存在「uid_1.jpg」。

的源代碼:

string fileName = "uid_1.jpg"; 
string imageUrl = "/upload/headImage/" + fileName; 
fileName = Path.Combine(Server.MapPath("~/upload/headImage/"), fileName); 
if (File.Exists(fileName)) 
{ 
    File.Delete(fileName); 
} 

upload.SaveAs(fileName); 

誰能告訴該怎麼辦? 謝謝。

回答

1

我明白了! 當我使用chmod 777 /var/www/www.mysite.com/upload/headImage/,我發現我可以上傳文件到服務器。

+0

但我想也許這是最好的方法,其他人可以告訴我一個更好的解決方案? – zhoufoxcn 2012-08-10 00:33:04