【问题标题】:Visited pages can be viewed after Logout when browser back button is clicked. How do i avoid?单击浏览器后退按钮,注销后可以查看访问过的页面。我该如何避免?
【发布时间】:2014-09-25 04:14:33
【问题描述】:

当我两次单击浏览器的后退按钮时,它会将我带到访问过的页面.. 第一次当我在注销后单击返回时,它会按预期将我带到登录页面,但是当我再次单击返回时它会带我访问页面.. 我该如何阻止呢?任何想法 这是我的代码:

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

注销链接按钮中的代码:

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

        }           
    }

【问题讨论】:

    标签: c# asp.net session


    【解决方案1】:

    您可以将无缓存 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

    【讨论】:

    • 感谢您的回复...这不起作用...当我单击浏览器的后退按钮两次时。
    • 您使用的是什么浏览器?我知道与旧浏览器可能存在一些冲突。
    • IE.11...第一次运行良好,再次点击后会带我进入访问过的页面
    • 听起来那些旧页面已被缓存,因为它们不包含元标记 - 请查看页面源以确保。
    • @keerthi 这是解决您问题的方法还是有其他问题?
    猜你喜欢
    • 1970-01-01
    • 2013-11-08
    • 2023-04-03
    • 1970-01-01
    • 2018-08-14
    • 2016-01-20
    • 2016-09-25
    • 2022-01-09
    • 2012-07-09
    相关资源
    最近更新 更多