2015-12-10 70 views
1

我有這種情況,當我從global.asax文件數據持久存儲數據時,必須將數據存儲在應用程序變量中。 如果我寫的應用程序變量中的商店數據相同的代碼從任何aspx頁面數據丟失一段時間後,我想知道爲什麼發生了,請在下面建議是我的代碼?爲什麼應用程序變量數據在一段時間後丟失

//storing data in application variable from aspx page 
protected void getApplicatinVariable_Click(object sender, EventArgs e) 
{ 
HttpContext.Current.Application[paramTypeId] = GetSelectedParameter(paramTypeId, flag);//fuction retruning string data 
HttpContext.Current.ApplicationApplication["GroupUserListCache"] = CacheClass.GetGroupUserListCache();//get userlist 
HttpContext.Current.ApplicationApplication["EquipListCache"] = CacheClass.GetAlarmEquipListCache(); 
} 

//from global.asax file in dis case data persist. 
Application[paramTypeId] = CacheClass.GetSelectedParameter(paramTypeId, ""); 
Application["GroupUserListCache"] = CacheClass.GetGroupUserListCache();//get userlist 
Application["EquipListCache"] = CacheClass.GetAlarmEquipListCache();//CacheClass.SetEquipment(); 

回答

3

根據Microsoft's documentationHttpApplicationState其是用於HttpContext.Current.Application基礎對象:

ASP.NET應用程序是的所有文件,頁,處理程序,模塊和代碼的範圍內的總和一個虛擬目錄及其在一臺Web服務器上的子目錄。

當客戶端首次從特定的ASP.NET應用程序虛擬目錄中請求任何URL資源時,將創建HttpApplicationState類的單個實例。爲Web服務器上的每個ASP.NET應用程序創建單獨的單個實例。然後通過內部Application對象暴露對每個實例的引用。

應用程序狀態不是跨Web場(跨多個服務器託管應用程序)或Web應用程序(在同一臺計算機上跨多個進程託管應用程序)共享。

因此,從技術上講,如果您處於共享環境中,它將不會持久,但對於單個應用程序,它只在第一個請求發生時啓動該類的一個實例。

+0

你能鏈接你的報價來源嗎? – user1666620

+0

爲您添加了鏈接 –

+0

已同意,但我在本地計算機上託管了此應用程序,並且只有一個應用程序託管在那裏。所以沒有網絡農場或網絡花園的機會,我正在我的局域網中測試它。仍然在一段時間後失去。 –

相關問題