[英]File uploading into server
我正在制作一個具有圖像上傳模塊的網站。在我的本地主機服務器中,它運行正常。 這意味着我可以上傳圖像並保存。 但是,當我托管我的解決方案時,我得到了一個錯誤。 即,拒絕訪問路徑。
這是我使用的代碼...
string fileName = FileUpload1.FileName.ToString();
string uploadFolderPath = "~/up_foto/";
string filePath = HttpContext.Current.Server.MapPath(uploadFolderPath);
FileUpload1.SaveAs(filePath + "\\" + fileName);`
這是怎么了..請幫助我....在此先謝謝....
如果代碼在本地運行,恐怕代碼沒有問題。 相反,您必須確保在主機環境上,用戶“ IUSER”或“ IIS_IUSER”等是否具有對上載文件夾的訪問權限(讀取/寫入)。
由於您收到“拒絕訪問路徑”的信息,是否檢查了要上傳的文件夾是否具有寫權限
您可以使用Path.combine或server.mappath(不要忘記在名稱空間中添加System.IO)
string fileName = FileUpload1.FileName.ToString();
string uploadFolderPath = "~/Uploads/Images/";
string filePath1 = Server.MapPath(uploadFolderPath + fileName);
要么
string fileName = FileUpload1.FileName.ToString();
string uploadFolderPath = "~/Uploads/Images/";
string filePath = Server.MapPath(uploadFolderPath);
string filePath1= Path.Combine(filepath1 + fileName);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.