Search code examples
c#asp.netasp.net-2.0logout

Avoid displaying of previous pages after logout ASP.NET C# 2.0


I am having problem with logout. After Logging out of the application also, when a user presses browser back button those secured pages are displaying.

And also the page load event is not firing for browser back button. I am using master page and content page.

My logout functionality is in master page.

    Session.Clear();
    Session.Abandon();
    Session.RemoveAll();
    Response.Redirect("~/Default.aspx");

Here my login page is Default.aspx.


Solution

  • What you need to do is, just don't cache the page that you want to prevent user from access after you logs out:

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