Disable of viewing previous page in asp.net

后端 未结 2 1234
长情又很酷
长情又很酷 2021-01-22 01:39

In my project i want to deny going back to the page when i click back button in toolbar. How its possible in asp.net and c#. Thank you.

相关标签:
2条回答
  • 2021-01-22 01:56

    Just put this javascript in the html section of an aspx page above the head section.

    This causes every back to return with a forward.

    <script type = "text/javascript" >
    function disableBackButton()
    {
    window.history.forward();
    }
    setTimeout("disableBackButton()", 0);
    </script>
    

    plus have a look at this article http://www.4guysfromrolla.com/webtech/111500-1.shtml

    0 讨论(0)
  • 2021-01-22 01:59

    If you want to do this by code-behind.Put following code in Page_Load or Page_Init event of the page

    protected void Page_Init(object Sender, EventArgs e)
    {
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
    Response.Cache.SetNoStore();
    }
    
    0 讨论(0)
提交回复
热议问题