2015-08-21 19 views
1

我正在研究asp.net webforms。還有的用戶登錄頁面,如果用戶成功登錄,然後它通過SQL數據庫在webforms中傳遞會話的對象asp.net

Profiledata profiledata = new Profiledata(); 
profiledata.Fname = SelectReader.GetString(0); 
profiledata.Lname = SelectReader.GetString(1); 
profiledata.email = SelectReader.GetString(2); 
profiledata.password = SelectReader.GetString(3); 
\\if we print profiledata values here all values are shown correct           
Session["profile"] = profiledata; 

訪問在接下來的頁面後,我訪問

Profiledata profiledata = new Profiledata(); 
profiledata = (Profiledata)Session["profile"]; 

但它保存在類文件數據的對象中的所有數據在會話中顯示空例外在會話中找不到任何值

回答

1

如果您在會話填充前檢索會話值,則該值可能爲空。 如果您禁用了SessionState http模塊,或者您的代碼在HttpHandler中運行,但它沒有指定IRequiresSessionState或IReadOnlySessionState,則它也可以爲null

+0

這不能提供問題的答案。一旦你有足夠的[聲譽](http://stackoverflow.com/help/whats-reputation),你將能夠[評論任何職位](http://stackoverflow.com/help/privileges/comment);相反,[提供不需要提問者澄清的答案](http://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-c​​an- I-DO-代替)。 - [來自評論](/ review/low-quality-posts/11684635) – Mike

+0

請仔細閱讀本節:http://stackoverflow.com/help/how-to-answer瞭解答案應該如何工作。 SO不是一個通過答案討論問題的論壇。 – Mike

+0

我編輯了我的答案。我知道這不是一個論壇 – Emanuele