Avoid persisting data while refreshing

Asked

Viewed 159 times

1

I am recording a history log of accessed options while doing refresh on the page it is duplicating the data. How do I persist only on the request?

  • 1

    Welcome to Stack Overflow. Start doing a [tour] and see also [Ask]. Your question is very generic and will probably be closed if you do not include more details from the link [Edit].

  • What language are you using? Which language framework? Which server? What codes implement the actions that perform such duplication? Please edit your question and put more details?

1 answer

0


Regardless of the language the solution of the issue to be solved only with information from request sent by the browser. In this case we will use the chrome and firefox, as they both add a new header when the user gives a refresh or F5, that header is the Cache-Control with a value of max-age 0.

Implementation in ASP.NET MVC

public ActionResult Index()
{
    var cacheControl = Request.Headers["Cache-Control"];

    if (cacheControl != null) // opcional o `Equals("max-age=0")`
    {
        // "É refresh"
    } else {
        // Pode salvar o log
    }
    // restante do código
}

The internet explorer adds a parameter in the request depending on the version, will you see which you want to cover and adapt this solution.

  • I’m using IE11 how do I get this parameter? Chrome worked.

  • @Alunseralbuquerque I’m at work now and I won’t be able to reproduce the test to verify the difference, but if you have free time do an iteration on Request.Headers and Request.Param to try to notice any difference when it is F5 or not. If you observe using Chrome the Request.Headers increases a parameter

  • When I get home I can try to find the difference and tell you.

  • Then Maicon in Chrome he adds Request.Headers["CACHE-CONTROL"] when I refresh the page but I wanted to have this control also in IE11.

  • noticed something in the IE?

  • search for pragma

  • In IE11 it does not add.

  • http://stackoverflow.com/questions/7995009/ie-adding-http-header-pragma-no-cache

  • Maicon in IE Cache-Control comes private I don’t know if that’s why I can’t get it

  • @Alunseralbuquerque I’m testing here too and could not see any difference, only a doubt you block call the same action more than once?

  • So my purpose is to save a log when the user enters a given page and if for some reason he gives refresh I should not save in the bank.

Show 6 more comments

Browser other questions tagged

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