0

I have gone through some links and spend hours but My page still loads after log out on clicking back button. here is my log out page code which i tried.

protected void Page_Load(object sender, EventArgs e)
    {
    if(Session[Constants.KeyValues.UserProfileSession]== null)
     {
            Response.Redirect("www.google.com", true);
     }          

        ////Clear cookie and redirect user to login page (Landing page before login).
        Response.AddHeader("pragma", "no-cache");
        Response.AddHeader("cache-control", "private");
        Response.CacheControl = "no-cache";
        Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetNoStore();
        FormsAuthentication.SignOut();
        Response.Cookies.Clear();

        HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));

        HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
        HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        HttpContext.Current.Response.Cache.SetNoStore();


        Session.Clear();
        Session.Abandon();
        Session[Constants.KeyValues.UserProfileSession] = null;            
        Response.Write("<script type=\"text/javascript\">window.location.replace('www.google.com');</script>");
        //Response.Redirect("www.google.com", true);
    }

here is my html page

<!doctype html>
<html lang="ko">
<head>
    <title></title>
    <meta http-equiv="Cache-Control" content="no-cache" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
    <script type="text/javascript">
        function ClearHistory() {
            var backlen = history.length;
            history.go(-backlen);
            window.location.href = www.google.com
        }
    </script>
</head>
<body onload="ClearHistory();">
</body>
</html>

Here is the code of the page load where member go after login

protected void Page_Load(object sender, EventArgs e)
    {
    if(Session[Constants.KeyValues.UserProfileSession]== null)
     {
            Response.Redirect(SPContext.Current.Site.Url + "/_layouts/ABC/ShoppingLandingBeforeLogin.aspx", true);
     }  }

Here are the links i have tried.

How to clear browser cache when user log off in asp.net using c#?,

How to prevent browser and proxy caching of web pages,

Browser back button issue after logout,

Clear History using javascript,

back-button-of-browser-issue-in-asp-net-logout

Community
  • 1
  • 1
love thakker
  • 460
  • 2
  • 13
  • 29
  • It's not the cacheability of the logout page you need to change - it's the cacheability of the page that you are going back to. What are the caching headers on that page? – Tim Rogers Aug 28 '14 at 09:12
  • I don't want user be redirect to the member page after log out. I can't disable back button but can clear catch of browser. Or any other method to achieve my goal. – love thakker Aug 28 '14 at 09:13
  • @Tim :I have added code of the page that loads when we click on back button. But that page is coming from cache so not able to check the session null value. – love thakker Aug 28 '14 at 09:21
  • @lovethakker What are the cache headers when that page is first loaded? If that page is cached by the browser, it doesn't matter what cache headers you set on the logout page - it won't affect any other pages. – Tim Rogers Aug 28 '14 at 09:40
  • @Tim : I am adding Meta tags in all pages which are in the Log out page. but still i am not able to remove them from cache. – love thakker Aug 28 '14 at 09:42

1 Answers1

0

Try to use this, it works across all browsers.

    Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
    Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.0.
    Response.AppendHeader("Expires", "0"); // Proxies.
  • team : No progress at all. Can u suggest anything else that can help me out of this? – love thakker Aug 28 '14 at 13:00
  • I have read Post [back-button-issue-after-logout](http://geekswithblogs.net/Frez/archive/2010/05/18/back-button-issue-after-logout-in-asp.net.aspx). I have implement it in my page. It works well. The only Point to remember is -> do not redirect through page load. Thanks. – love thakker Sep 16 '14 at 08:12