I need some pages not to be cached on a Classic ASP app, but I've tried every possible combination of headers and nothing seems to work:
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 1
Response.CacheControl = "no-cache; private; no-store; must-revalidate; max-stale=0; post-check=0; pre-check=0; max-age=0"
Response.AddHeader "Cache-Control", "no-cache; private; no-store; must-revalidate; max-stale=0; post-check=0; pre-check=0; max-age=0" ' Same as previous line, I know, just in case.
Response.AddHeader "Pragma", "no-cache"
Response.AddHeader "Expires", "-1"
I've also tried restarting both the website and IIS, to no avail. When I leave the page and return to it using the browser's back button, it doesn't reload.
What am I missing here?
EDIT: After a lot of more googling, I have found and implemented this JavaScript solution, it's not bullet-proof since it's client-side, and I would prefer a Server-Side solution, but it does the job!
Still, I would like to hear about any server-side options.
You are operating under the impression that the result of the browser's back button is related to HTTP caching, it is not.
The provision of the back button is at the discretion of the browser which is from a HTTP stack point of view the application. An application has no obligation to consider the caching requirements of any http request(s) that was used to render the contents of a window. Indeed many browsers are capable of displaying content delivered through other protocols than http.
Consider the most common scenario for using the back button. A user gets some search results from a web search engine (google, bing, ...), clicks on one of the results, quickly sees that the content is not what they were looking for and clicks the back button. In order to optomise the user's experience most browsers will hold on to many of the resources (even the window into which the page is rendered) of a page when navigation from the page occurs. The back button can then be implemented by reassembling those resources or even simply making the original window visible again.
Seem right.. try using this.
Run these statement before sending any HTML to the user, that is before any Response.Write
or <%=foo()%>
Response.Buffer = True
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
Corrected the misspelled word Response.
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