2013-03-14 75 views
0

我使用的代码下面一行用asp.net MVC4.浏览器后退按钮问题iasp.net MVC4

[OutputCache(NoStore = false, Duration = 0, VaryByParam = "None")] 
     public ActionResult Logout() 
     { 
      try 
      { 
       if (Session["username"] != null) 
       { 
        Session.Abandon(); 
        Session.Clear(); 
        Session.RemoveAll(); 
        Session["username"] = null; 
        Response.Cache.SetCacheability(HttpCacheability.NoCache); 
        Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1)); 
        Response.Cache.SetNoStore(); 
        return RedirectToAction("Index", "AdminPanel"); 
       } 

       return RedirectToAction("Error", "Home"); 
      } 
      catch (Exception e) 
      { 
       return RedirectToAction("Error", "Home"); 
      } 
     } 

禁用注销后浏览器后退按钮问题,但是,有一个问题与此代码,假如我”第三页第一页是登录页面(Index.cshtml),第二页登录页面(home.cshtml),第三页页面是(about.cshtml)页面,现在我登录了,然后它会重定向到home.cshtml页面,我现在转到第三页about.cshtml,然后我请从about.cshtml页面注销,它会将我重定向到login.cshtml页面。现在,如果我点击浏览器后退按钮,然后重新定向about.cshtml页面,但用户无法更改或添加任何内容。 因此,让我知道是否有任何适当的代码或方法来解决这个问题。

回答

0

如果你把这个在呈现about.cshtml你的控制器的方法,它会按照您描述:

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

不太理想,但让你在正确的轨道上。基本上,浏览器在登录时会缓存about.cshtml。告诉注销方法不要缓存响应,因为它执行重定向而不是渲染,所以没有做太多的工作。