2012-10-24 72 views
3

使用会话我试图在清除会话中使用Session.Abandon();“注销”链接。注销后,我重定向回登录页面。但即使注销后,我也可以使用浏览器的后退按钮访问以前的页面。我该如何解决它?注销在asp.net

+0

如果从历史的重新加载(F5)的页面,你还能继续使用的网站?或者您是否重定向回登录屏幕? – Blachshma

+0

它会重定向到登录 – Sudix

回答

1

根据您的意见,您的会话已被放弃。

,你看到的是保存在浏览器缓存中的网页的“快照”。 只要在你的代码背后确保你有一个有效的会话,然后允许用户在你的页面上执行任何任务,你应该没问题。

有关如何尝试和禁用缓存的各种答案,以便按下后退按钮不会显示前一页 - 但只要它转到您的问题 - 您已注销,您的会话消失了...

+0

好的谢谢.. 然后,我必须清除会话是不是?如果我没有照顾后退按钮,是否有任何问题? – Sudix

+0

如果您在允许用户执行任何任务之前检查并确保您的会话有效,那么您很好。检查这个的好方法是在page_load事件中:如果会话无效 - >重定向到登录页面。这就够了...... – Blachshma

+0

好..谢谢兄弟 – Sudix

0

尝试把这个在你的后台代码:

Page.Response.Cache.SetCacheability(HttpCacheability.NoCache) 
+0

不工作........ – Sudix

+0

@Sudheesh你能解释一下? –

0

试试这个代码:

// Code disables caching by browser. Hence the back browser button 
// grayed out and could not causes the Page_Load event to fire 
Response.Cache.SetCacheability(HttpCacheability.NoCache); 
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1)); 
Response.Cache.SetNoStore(); 

,如果你想将其置于您可以添加在形式上ASPX类似的东西

<META Http-Equiv="Cache-Control" Content="no-cache"> 
<META Http-Equiv="Pragma" Content="no-cache"> 
<META Http-Equiv="Expires" Content="0"> 

或 可以在退出事件中设置此项:

protected void LogOut() 
{  
    Session.Abandon();  
    string nextpage = "Logoutt.aspx";  
    Response.Write("<script language="javascript">");    
    Response.Write("{");  
    Response.Write(" var Backlen=history.length;");  
    Response.Write(" history.go(-Backlen);");  
    Response.Write(" window.location.href='" + nextpage + "'; "); 
    Response.Write("}");  
    Response.Write("</script>"); 
} 

更多信息参见: http://www.codeproject.com/Tips/135121/Browser-back-button-issue-after-logout

+0

我试过最后一个页面重定向回来,但后退按钮的问题仍然存在 – Sudix

0

你需要禁用所有类型的缓存对浏览器对于页面:

Response.Cache.SetExpires(DateTime.UtcNow.AddYears(-4)); 
Response.Cache.SetValidUntilExpires(false); 
Response.Cache.SetCacheability(HttpCacheability.NoCache); 
Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); 
Response.Cache.SetNoStore(); 
Response.ExpiresAbsolute = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0)); 
Response.Expires = 0; 
Response.CacheControl = "no-cache"; 
Response.AppendHeader("Pragma", "no-cache"); 
Response.Cache.AppendCacheExtension("must-revalidate, proxy-revalidate, post-check=0, pre-check=0");