Prevent User From Going Back After Clicking Logout

Posted on 2009-04-21
Last Modified: 2012-06-27
Our client has pointed out to us recently that after a user clicks logout, they can still click the back button and see pages and information.  This is true.  If the user attempted to click on a link or refresh the page THEN, because they are logged out, they would be redirected to the login page.

Is there a way to prevent this behavior?  I don't want to block the back button.  I can't think of a way that will stop a page from showing when they are logged out but simply click the back button.  I have noticed however, that with my online bank account, if i click logout and then the back button it takes me straight to a login page.
Question by:davidcahan
    LVL 13

    Expert Comment

    see if that could help
    LVL 13

    Expert Comment

    this is c#

        protected void lbLogout_Click(object sender, EventArgs e)
            string nextpage = "Login.aspx";
            Response.Write("<SCRIPT LANGUAGE=javascript>");
            Response.Write(" var Backlen=history.length;");
            Response.Write(" history.go(-Backlen);");
            Response.Write(" window.location.href='" + nextpage + "'; ");

    Open in new window


    Accepted Solution

    that didn't work for me.  However, I did some research and found that as long as I don't cache the pages then a user can't get to any private data after they logout and then hit the back button.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now