In a controller action, returning an IActionResult, how do I set an expires header?
I found this, but it seems to relate to server side caching, not simply setting a response header. I feel this should be really straightforward !
The HTTP Expires header is a response-type header, the fundamental way of controlling the caches present. The expire header contains the date and time which denotes the period where the object can stay alive.
Adding Expires Headers is important to reduce HTTP requests which reduces the time it take for the server to communicate with the browser. It also allows your users to reuse the cache files that have been stored in the browser to reduce the amount of files they need to download.
You can inside your contoller set the header:
string ExpireDate = DateTime.UtcNow.AddMinutes(60).ToString("ddd, dd MMM yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
Response.Headers.Add("Expires", ExpireDate + " GMT");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With