Browser Back Button Working After Logout from Asp.Net application

3 Comments | 4025 Views | Post by: Admin | Tags: Browser Back Button Working, After Logout from Asp.Net application,Browser Back Button,Logout


While begin logout from the asp.net web application a use can still move to the previous page using the browsers back button.


While begin logout from the asp.net web application a use can still move to the previous page using the browsers back button.During the log out event, Session is cleared and caching is disabled but the previous page is still shown. So, how can we work around this?

All browsers provide the History Option to go back to previous visited web pages(both forward and backward). The browser cache the visidted page and the History butons-  backward and forward is used to to move from oder visted pages to newer visited page.

So, to fix this type of issue, we need to make sure that page do not get cahced. I'm showing to method to resolve this issue.

Option 1 - Code behind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class option_one : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
        Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
        Response.Cache.SetNoStore();
    }
}

Option 2 - Works on any page

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="option-two.aspx.cs" Inherits="option_two" %>

"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

"http://www.w3.org/1999/xhtml">
"Head1" runat="server">
        
        "Cache-Control" content="no-cache" />
        "Pragma" content="no-cache" />
        "Expires" content="0" />
    

    "form1" runat="server">
    

In the above code, you can paste the code in the master page for the authenticated pages or alternatively, if there is no fixed master page for authenticated pages - then, it needs to be places on all all required pages.

Conclusion:-
so, we have learned and resolve the issue related with Browser Back Button Working After Logout from Asp.Net application

 

Download Source Codes


Post Comments

if you have some suggestion, question, request on Browser Back Button Working After Logout from Asp.Net application.

Please use the comment box to express your views.

 

Comments:

loading...