Net 4 and C#.
I would need set send to Browser Cache-Control (Cache-Control: no-cache
) in the HTTP Response header for a Web Form page.
Any idea how to do it?
Thanks for your time.
To set the header to public, private or no-cache, use the Response. Cache. SetCacheability method. Response.
Without the cache control header the browser requests the resource every time it loads a new(?) page.
If you want to enable Cache-Control for all files, add Header set line outside the filesMatch block. As you can see, we set the Cache-Control header's max-age to 3600 seconds and to public for the listed files.
Cache-control is an HTTP header used to specify browser caching policies in both client requests and server responses. Policies include how a resource is cached, where it's cached and its maximum age before expiring (i.e., time to live).
Try this:
Response.AppendHeader("Cache-Control", "no-cache");
However, you should know that this header alone won't give you a reliable cross-browser way to prevent caching. See this answer for more accurate solution: Making sure a web page is not cached, across all browsers
In MVC you can set it in the Controller class, so the View not use cache;
public ActionResult User()
{
Response.CacheControl = "no-cache";
return View();
}
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