How to disable browser caching?

Posted by Naresh2k3406 under ASP.NET on 3/27/2012 | Points: 10 | Views : 3410 | Status : [Member] | Replies : 2
How to avoid resource(image, css files, javascript etc.) caching by browser in asp.net website?




Responses

Posted by: Rajni.Shekhar on: 3/27/2012 [Member] Bronze | Points: 25

Up
0
Down
using following code:

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (User.Identity.IsAuthenticated)
Response.ClearHeaders();
Response.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1
Response.AppendHeader("Cache-Control", "private"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1
Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1
Response.AppendHeader("Keep-Alive", "timeout=3, max=993"); // HTTP 1.1
if (Request.UrlReferrer == null)
{
Response.Redirect("~/login.aspx");
}
}

Thanks,
Rajni Shekhar

Naresh2k3406, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response