Prevent user from seeing previously visited secured page after logout

前端 未结 5 1765
陌清茗
陌清茗 2020-11-21 05:59

I have the requirement that the end user should not be able to go back to the restricted page after logout/sign out. But currently the end user is able to do that by the bro

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-21 06:28

    The simplest way to do it without disabling the browser back buton is by adding this code to the page_load event for the page that you don't want the user to go back to after logging out:

    if (!IsPostBack)
        {
            if (Session["userId"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            else
            {
            Response.ClearHeaders();
            Response.ClearContent();
            Response.Clear();
            Session.Abandon();
            Session.Remove("\\w+");
            Response.AddHeader("Cache-Control", "no-cache, no-store, max-age = 0, must-revalidate");
            Response.AddHeader("Pragma", "no-cache");
            Response.AddHeader("Expires", "0");
            }
        }
    

提交回复
热议问题