Wednesday, April 28, 2010

Prevent Page from being Cached in ASP.NET

In ASP.NET Page can be prevent from being cached by IIS. The following VB.NET code forces IIS to reprocess the page each time it's called.


Sub nocache_store()
'HttpContext.Current.Session.LCID = 2057
With HttpContext.Current
'.Session.LCID = 2057
.Response.AppendHeader("Pragma", "no-cache")
.Response.AppendHeader("Cache-Control", "no-cache")
.Response.AppendHeader("Cache-Control", "no-store")
.Response.AppendHeader("Cache-Control", "must-revalidate")
.Response.CacheControl = "no-cache"
.Response.Expires = -1
.Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache)
.Response.Cache.SetAllowResponseInBrowserHistory(False)
.Response.ExpiresAbsolute = New DateTime(1900, 1, 1)

End With
End Sub



click here to Convert Code from vb.net to c#.net

No comments:

Post a Comment