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?
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?
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
.
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.