Search code examples
asp.netauthenticationforms-authenticationhttp-authentication

Back button must not go to previous page after signing out


I am developing an asp.net web site and I am not using inbuilt authentication controls of asp.net. I have created manually tables for users for site.

What I want is as follows

  • After logging in user can access the pages (that is already done)
  • When user press sign out (user goes to specific page - example - default.aspx)
  • Now when user press "back" button of browser, it must not go to previous page (that is done in Yahoo pages - I want to implement the same)

Solution

  • To prevent users from seeing the previous page when pressing the back button you need to instruct the browser not to cache this page:

    Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
    Response.Cache.SetValidUntilExpires(false);
    Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetNoStore();
    

    You could put this code in all authenticated pages, thus preventing them from being cached on client browsers.