問:為什么當(dāng)我在InProc模式下使用Session會經(jīng)常丟失? 答:該問題通常是由于應(yīng)用程序被回收導(dǎo)致的,因?yàn)楫?dāng)使用進(jìn)程內(nèi)Session時(shí),Session是保存在aspnet_wp進(jìn)程中,當(dāng)該進(jìn)程被回收Session自然也就沒有了,確定該進(jìn)程是否被回收可以通過查看系統(tǒng)的事件查看器獲得信息。 具體信息請參考: Session variables are lost intermittently in ASP.NET applications http://support.microsoft.com/default.aspx?scid=kb;en-us;Q316148 在1.0的時(shí)候也有一個bug會導(dǎo)致工作進(jìn)程被回收并重啟,該bug已經(jīng)在1.1和sp2中修復(fù)。 關(guān)于該bug的詳細(xì)信息請參考: ASP.NET Worker Process (Aspnet_wp.exe) Is Recycled Unexpectedly. http://support.microsoft.com/default.aspx?scid=kb;en-us;Q321792
問:如何將SortedList存儲到Session或者Cache里? 答:請參考下面的方法: SortedList x = new SortedList(); x.Add("Key1", "ValueA"); x.Add("Key2", "ValueB"); 保存到Session中: Session["SortedList1"] = x; 使用下面方法獲得之: SortedList y = (SortedList) Session["SortedList1"]; Chahe則同理。
問:我為什么會獲得這樣的錯誤信息“Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive”? 答:這個問題可能在一個已經(jīng)安裝了Microsoft Visual Studio .NET開發(fā)環(huán)境的機(jī)器上,再安裝Window Sharepoint Server(WSS)后出現(xiàn)。 WSS ISAPI過濾器會處理所有的請求。當(dāng)你通過虛擬目錄瀏覽一個ASP.NET的應(yīng)用程序時(shí),ISAPI過濾器不會給文件夾目錄分配URL。 解決方法是:不要再安裝了WSS的機(jī)器上使用Session。 詳細(xì)信息請參考: Session state cannot be used in ASP.NET with Windows SharePoint Services http://support.microsoft.com/default.aspx?scid=kb;en-us;837376