Expired web page when I return to the page by the browser button. Previous page c/ postback

Asked

Viewed 578 times

1

In my current application, I have a content list page, which has a small form above to perform "filters" in Gridview below so yes select an item and go to the next page edit the same.

What happens is that when I’m on the editing page and try to go back to the listing page by clicking on the browser button, it displays "Expired Web Page" (only when I selected a filter for 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();
        }

    }
  • This is the normal behavior of the browser. All pages that have been obtained by a POST request expire. They don’t even reach the server, so the solution you used doesn’t work. It’s a protection system.

  • Is there any way to at least switch to the "last" page? I thought because in my system many users are used to clicking the back button of the browser and not the back button of the page. At least trigger an alert "You can’t come back here, use the back button on the page."

1 answer

1


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

There is no guaranteed way to disable the browser "back" button. However, if the system does not need to run on IE 9-, it is possible to use the API to manipulate browser history, and with this do a sort of gambiarra. The API works on Firefox, Chrome, Safari, Opera or IE 10+.

Code example:

<!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>

To gambiarra consists of creating an infinite loop in the browser history, so the "back" button always ends up going back to the same page (which is the current page).

  • Detail: This technique will cause the current URL to have added to it the character #.

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

  • Detail 3: Test the behavior to see if it won’t mess up your system.

*Based on that response from the OS en.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.