PROWAREtech

articles » archived » asp-net » browser-cache-control

ASP.NET: Web Browser Cache Control

Stop browser caching of Web Forms (.NET Framework).

By default — what most internet users leave their web browsers at — web pages are cached but it is easy to make the browser reload them everytime.

<%@ Page Language="VB" %>
<script runat="server">
	Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

		Response.AddHeader("Pragma", "no-cache") ' HTTP/1.0
		Response.CacheControl = "no-cache"
		Response.Cache.SetAllowResponseInBrowserHistory(False)
		Response.Cache.SetCacheability(HttpCacheability.NoCache)
		Response.Cache.SetNoStore()
		Response.Expires = -1
		
		time.InnerHtml = DateTime.Now.ToString()
	End Sub
</script>
<html>
	<head><title></title></head>
	<body>
		<span id="time" runat="server"></span>
	</body>
</html>
<%@ Page Language="C#" %>
<script runat="server">
	void Page_Load(object sender, System.EventArgs e)
	{
		Response.AddHeader("Pragma", "no-cache"); // HTTP/1.0
		Response.CacheControl = "no-cache";
		Response.Cache.SetAllowResponseInBrowserHistory(false);
		Response.Cache.SetCacheability(HttpCacheability.NoCache);
		Response.Cache.SetNoStore();
		Response.Expires = -1;
		
		time.InnerHtml = DateTime.Now.ToString();
	}
</script>
<html>
	<head><title></title></head>
	<body>
		<span id="time" runat="server"></span>
	</body>
</html>

PROWAREtech

Hello there! How can I help you today?
Ask any question

PROWAREtech

This site uses cookies. Cookies are simple text files stored on the user's computer. They are used for adding features and security to this site. Read the privacy policy.
CLOSE