单击浏览器后退按钮后,可以在注销后查看访问的页面。我该如何避免?

时间:2014-09-24 19:34:46

标签: c# asp.net session

当我点击浏览器的后退按钮两次时,它带我去访问过的页面..这是我第一次点击退出后退出它带我按预期登录页面但是当我再次点击它带我访问过的页面..我如何阻止?任何的想法 这是我的代码:

 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;
            }
        }
    }

Logout LinkBut​​ton中的代码:

    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);

        }           
    }

1 个答案:

答案 0 :(得分:2)

您可以将no-cache Meta HTML标题添加到您不想缓存的页面。

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

这是一个类似的问题:How to prevent user from going back to the login-page after successful login using back button

这似乎是一个很好的演练:

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