Web page expired when I return to the page through the browser button. Previous page with postback

1

In my current application, I have a content list page, which has a small form above to "filter" the GridView below to select an item and go to the next page edit it.

What happens is that when I'm on the edit page and try to go back to the list page via the browser button, it displays "Expired Web Page" (only when I selected some filter on the listing page).

I have tried to use the code below, to try to intercept the load and force a reload of the page without the same values but without success.

    private void Page_PreRender(object sender, System.EventArgs e)
    {
        if (IsPostBack && !Request.UrlReferrer.AbsolutePath.Contains("origem-listar.aspx"))
        {
            Response.Write("<html><head><script>location.replace('" + Request.Url + "');\n" + "</script></head><body></body></html>\n");
            Response.End();
        }

    }
    
asked by anonymous 16.06.2014 / 21:04

1 answer

1

Actually, when returning to a page that was generated through information sent via POST , the browser may say that the page has expired, or say that it will submit the information again, which may not always be what it wants.

There is no guaranteed way to disable the "back" button in browsers. However, if the system does not need to run in IE 9-, you can use the API to manipulate browser history, and thereby make a kind of gambiarra . The API works in Firefox, Chrome, Safari, Opera or IE 10+.

Code sample:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="pt-br">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>
        Título
    </title>
    <script type="text/javascript">
        history.pushState({page: 1}, "Título", "#");
        window.addEventListener("popstate", function(event) {
            history.pushState({page: 1}, "Título", "#");
        });
    </script>
</head>
<body>
...
</body>
</html>

Gambiarra is to create an infinite loop in the browser's history, so the "back" button always returns to the same page (which is the current page).

  • Detail: This technique will make the current URL add to it the # character.

  • Detail 2: Depending on how many times the user is redirected to this page, and how the system is used, the history may grow a lot.

  • Detail 3: Test the behavior to see if it will not disrupt your system.

* Based on this OS response .

    
17.06.2014 / 17:52