我有一個上傳圖片的代碼片段。上傳時,它暫時將該文件存儲在會話中。然後點擊「保存」,它將文件保存在數據庫中。爲什麼顯示「無法訪問關閉的文件」錯誤?爲什麼只在服務器上?
我的機器上沒有問題,但是在服務器上,每當我嘗試上載某些文件,然後單擊「保存」時,它就會顯示錯誤信息「無法訪問已關閉的文件」。在谷歌搜索它,我讀了here,這是由於大文件上傳。我想確認,是我上傳大文件的問題?或者它可能是別的東西? 另外,爲什麼我沒有得到這個在我的機器上,只有在服務器上?
編輯:順便說一下,錯誤出現了,當file size > 80kb
守則上傳文件:關於儲蓄
public ActionResult StoreLogoInSession(HttpPostedFileBase file, int assetID)
{
string filename = null;
if (ValidateOnUpload(file))
{
Session.Add("TempLogo", file);
filename = file.FileName;
Session.Add("filename", filename);
}
return RedirectToAction("Edit", new { id = assetID });
}
代碼(這是發生錯誤時):
public ActionResult SaveLogo(LogoModel m, int assetID)
{
HttpPostedFileBase file = (HttpPostedFileBase)Session["TempLogo"];
var logoModel = new LogoModel();
var asset = this.GenerateAssetForUploadFile(file, (int)m.Asset.AccountID, m.Asset.TextContents, m.Asset.AssetName);
this.LogoManagementFacade.SaveLogo(asset);
logoModel.Asset = asset;
this.LogoModelList.Add(logoModel);
}
使用會話不好。使用Session來存儲上傳的文件是一種令人憎惡的行爲。請不要。 – 2012-07-26 11:11:17
好的,但是我現在面臨的這個問題呢? – 2012-07-26 11:14:02
您面臨的問題是設計問題。不要爲此任務使用Session。我的意思是你正在使用錯誤的工具進行這項工作,現在你在問爲什麼它不起作用。不知道該告訴你什麼。祝你好運,這個問題。我無法幫助。我可以給你的最好建議是儘快擺脫這個Session。 – 2012-07-26 11:14:31