2011-10-07 65 views
0

我有以下注销代码。当它注销时,但当按下后,它不应该去以前访问的页面,但它确实。注销C#不工作

//当登录

if (txtPassword.Text == password) 
       { 
        Session["Login"] = true; 
        Response.Redirect("AdminControlPanel.aspx"); 
       } 

//当注销

Session["Login"] = false; 
      Session.Abandon(); 
      FormsAuthentication.SignOut(); 
      Response.Cache.SetCacheability(HttpCacheability.NoCache); 
      Response.Cache.SetAllowResponseInBrowserHistory(false); 
      Response.Redirect("~/index.aspx"); 

//上adminpanel.aspx

if (!this.Page.IsPostBack) 
      { 
       if (this.Session["Login"]==null || (bool)this.Session["Login"]==false) 
       { 
        base.Response.Redirect("~/index.aspx"); 
       } 
      } 

检查有什么不对呢?

+0

穿上它断点,并检查会话[“登录”]的价值。 –

+0

可能重复? http://stackoverflow.com/questions/2686946/asp-net-authentication-login-and-logout-with-browser-back-button –

+0

你无法控制浏览器,所有代理之间的等等远处理用户按“后退”。这可能是为什么如此多的注销页面要求用户关闭浏览器窗口。只要数据曾经在浏览器中查看过,它可能在一个或多个高速缓存中并且可以复活,缓存控制可能会或可能不会被链中的任何中间人正确承认。 –

回答

3

尝试设置Cache-Control

Response.Cache.SetCacheability(HttpCacheability.NoCache); 
Response.Cache.SetAllowResponseInBrowserHistory(false); 
0

可能有可能是问题,当你分配值到session变量

把一个破发点中if (txtPassword.Text == password)和检查 会发生什么。

if (!this.Page.IsPostBack) 
      {    
      if (!string.IsNullOrEmpty((string) Session["Login"])) 
      { 
        var result = Convert.ToBoolean(Session["Login"]); //put a break point there also and check what values it getting 
       } 


      } 
+0

它不能与“” – Heena

+0

你可以把你的代码分配给会话的值 –

+0

更新了问题 – Heena