0

when i click back button of the browser twice its taking me to visited pages.. for the first time when i click on back after log out its takes me to Login in page as expected but when i click back again its taking me to visited pages.. How do i stop that?? Any idea Here is my Code:

 protected void Page_Load(object sender, EventArgs e)
    {
        Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
        Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.0.
        Response.AppendHeader("Expires", "0");

        if (!IsPostBack)
        {
            LoginMultiview.ActiveViewIndex = 0; /////  Login Page.
        }
        else
        {
        }         
    }

 protected void btnsubmit_Click(object sender, EventArgs e)
    {
        if (AuthenticateUser(txtUserName.Text, txtPassword.Text))
        {
            string Username = Session["username"].ToString();
            string Password = Session["password"].ToString();
            if (Session["username"] != null && Session["password"] != null)
            {
                GetEmployeeId(Username, Password);

                LoginMultiview.ActiveViewIndex = 1;

                GetManagerTimeSheets();
            }
            else
            {
                Response.Redirect("Login.aspx");
                LoginMultiview.ActiveViewIndex = 0;
            }
        }
        else
        {
            string Username = Session["username"].ToString();
            string Password = Session["password"].ToString();
            if (Session["username"] != null && Session["password"] != null)
            {
                ddlWeeks.DataSource = GetWeeksDropdownData();
                ddlWeeks.DataBind();

                Response.Write("WELCOME" + " " + Username);
                LoginMultiview.ActiveViewIndex = 2;
            }
            else
            {
                Response.Redirect("Login.aspx");
                LoginMultiview.ActiveViewIndex = 0;
            }
        }
    }

Code with in Logout LinkButton:

    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        Session.Clear();
        Session.RemoveAll();
        Session.Abandon();
        if (Session["username"] == null&& Session["password"]== null)
        {
            Response.Redirect("Login.aspx", true);

        }           
    }
keerthi
  • 37
  • 1
  • 9

1 Answers1

2

You can add no-cache Meta HTML headers to the pages you don't want cached.

<META Http-Equiv="Cache-Control" Content="no-cache"/>
<META Http-Equiv="Pragma" Content="no-cache"/>
<META Http-Equiv="Expires" Content="0"/>

This is a similar question: How to prevent user from going back to the login-page after successful login using back button

This seems to be a good walkthrough:

http://www.codeproject.com/Tips/135121/Browser-back-button-issue-after-logout

Community
  • 1
  • 1
user1666620
  • 4,800
  • 18
  • 27