ASP.Net: Expiring a page when navigating back

Posted by K2so on Stack Overflow See other posts from Stack Overflow or by K2so
Published on 2010-03-17T16:05:42Z Indexed on 2010/03/17 16:31 UTC
Read the original article Hit count: 175

Basically all pages on this site I am building cannot be accessed when the user clicks on "Back" (or with key control) in the browser, and the page should expire if one is trying to navigate back in history.

I put into Global.asax::Application_BeginRequest

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

This would clear out the cache and disallow going back to any pages when the user is logged out, but doesn't do the job while the user is logged in.

I saw posts where people suggested using a javascript approach, by calling

    History.Forward(1)

on the page. But I wouldn't like to do this, as it will require javascript enabled to work (which user can disable).

Appreciate any suggestions.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about browser