Avoid persisting data when refreshing

1

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

    
asked by anonymous 30.06.2015 / 15:02

1 answer

0

Regardless of language, the solution to the question is to be solved only with request information sent by the browser. In this case we will use chrome and firefox , as they both add a new header when the user gives refresh or f5 , this header is 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
}

internet explorer adds a parameter to the request depending on the version, it is up to you to see which one you want to span and adapt that solution.

    
30.06.2015 / 16:06