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