Is it possible to detect server page refresh (F5)?

... compared to requests for the usual behavior of clicks on links. I thought I could use this to throw some cached stuff into the server. For a more targeted audience, this may be a relative natural way to clear the cache, that is, graphs and charts.

To be clear - I use ASP.NET MVC

+4
source share
4 answers

I just checked out the three browsers that you are likely to need, and all three will add extra cache headers to the request when the page is refreshed. Perhaps you can verify that these headers throw server-side caching. It also seems a logical and natural way to do this.

  • IE: Adds "Pragma: no-cache"
  • Chrome: adds "Cache-Control: max-age = 0" and "If-Modified-Since: Tue, 17 Dec 2013 10:16:22 GMT" (disclaimer: time may vary)
  • Firefox: Adds "Cache-Control: max-age = 0"

I just checked this by refreshing this page in all three browsers and checking Fiddler. Perhaps there is a more complex logic that I have not caught.

+3
source

MVC, TempData . TempData, () , .

, Add, , :

public virtual ActionResult Add(Model model)
        {
            if(TempData.ContainsKey("yourKey"))
            {
                //it means that you reload this method or you click on the link
                //be sure to use unique key by request since TempData is use for the next request 
            }

            TempData.Add("yourKey", true);

            return View(model);
        }
+2

script :

<script>
        $(window).keydown(function (e) {
            if (e.which == 116) {
                e.preventDefault();
                var l = window.location;
                var lp = (l + "?").split('?');
                window.location = lp[0] + "?f5=1&" + lp[1];
                return false;
            }
        });
    </script>

, [ "f5" ] == "1"

URL-, cookie. - :

<script>
        $(window).keydown(function (e) {
            if (e.which == 116) {
                AddCookie("F5","1")
            }
        });
</script>

, cookie .

+1

, IsPostBack.

IsPostBack , , - , . , , , , , . , , , , , , (F5).

, F5 , - Enter , , .

EDIT: , , , . , IsPostBack MVC, -, :

ASP.NET MVC - IsPostBack ?

, , . , X.

X : 1. A, X. 2. B, B (). 3. F5 . - , .

4, " X ", , .

, , - SessionID. SessionID . , , .

1: A, . " " . A. , B. B , IsPostBack, . , , , . , " " (, ). " " , B, , . ' B; sessionID ( , , ).

2: B, " B" . B. B , IsPostBack. , , .

3: B, " B" . , . B , IsPostBack, , . " B" . " B" , B, , .

, . MVC, Request.HttpMethod=="POST"

, , , POST, , , , , POST. , . Nonce - .

0

All Articles