這裏的交易:我有一個網站,多人將共享相同的帳戶,並且每個人都應該能夠在上傳文件的頁面上保留他們上傳會話的文件列表。在文件上傳頁面控制器看起來像如何讓這個對象存在於會話中?
public class FileUploadController : Controller
{
// ...
private List<ThreePartKey> uploadedFiles = new List<ThreePartKey>();
public ActionResult Index ()
{
// ...
}
[HttpPost]
public ActionResult Index (HttpPostedFileBase file)
{
// ...
if (!errorOccured)
{
uploadedFiles.Add(new ThreePartKey { orgname = selectedOrgName, catname = selectedCatName, filename = fileNameNoExtension, fullfilepath = newFileUrlPathAndName });
}
// ...
}
,問題是,uploadedFiles
不斷得到重新初始化時[HttpPost] public ActionResult Index (HttpPostedFileBase file)
叫,意思是上載文件的用戶列表中只顯示最後上傳一個。所以我反而嘗試
private static List<ThreePartKey> uploadedFiles = new List<ThreePartKey>();
而且這一切都搞砸了,因爲所有登錄用戶都共享相同的列表。
有沒有簡單的方法來做我想做的事情?
如果多人共用同一個帳戶,那麼您的最佳選擇將是cookie。但是,如果您在下載時讓用戶登錄到獨一無二的帳戶,請使用數據庫存儲選項。 – Icemanind