2011-12-21 27 views
0

我正在一個asp.net(用c#)web應用程序,在這裏我有問題。如何檢查asp.net 4.0中的會話變量?

我有一個客戶頁面(customer.aspx),在此頁面中用戶可以填寫信息&如果用戶已經是註冊用戶,也可以更新。

因此,當這個頁面加載時,我檢查用戶是否登錄或不使用會話變量,如果設置了該會話變量,那麼用戶可以更新他/她的信息,這裏是在customer.aspx檢查代碼

protected void Page_Load(object sender, EventArgs e) 
     { 
      if (Session["customerID"] != null) 
      { 
       //here is my code 
      } 

     } 

但問題,如果我在註銷用戶點擊,然後一切都被罰款,但如果用戶只是按我的瀏覽器(IE 7.0)的返回按鈕,然後用戶allowded更新他/她的信息來源,這不應該發生。所以請告訴我這個問題的解決方案。

我logout.aspx代碼是在這裏:

protected void Page_Load(object sender, EventArgs e) 
     { 
      Session.Clear(); 
      Session.RemoveAll(); 
      Session.Abandon(); 
      Response.Redirect("login.aspx"); 
     } 

所以請建議我爲這個問題的解決方案。

回答

1

清除緩存

Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1)); 
Response.Cache.SetCacheability(HttpCacheability.NoCache); 
Response.Cache.SetNoStore(); 

this link may help you

0

它很可能是瀏覽器緩存頁面,而不是頁面重新加載。

確保緩存關閉,並且爲了安全措施,加載頁面時檢查會話狀態,如果頁面沒有填充則重定向。

 Response.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1 
     Response.AppendHeader("Cache-Control", "private"); // HTTP 1.1 
     Response.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1 
     Response.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1 
     Response.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1 
     Response.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1 
     Response.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1 
     Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1 
     Response.AppendHeader("Keep-Alive", "timeout=3, max=993"); // HTTP 1.1 
     Response.AppendHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); // HTTP 1.1 
     Response.Cache.SetCacheability(HttpCacheability.NoCache); 
+0

感謝亞當我customer.aspx頁面上我檢查的Page_Load中和redeirect他們,如果他們還沒有登錄,並且工作正常,但問題在於瀏覽器後退按鈕,即使在用戶退出按鈕後退出登錄後,所有信息都會顯示上一次登錄的用戶。 – Peeyush 2011-12-21 04:53:43

+0

建議您需要清除緩存。我已經更新了我的答案,向您展示了一些停止緩存的代碼。 – 2011-12-21 05:15:08