How to disable cachehttp://forums.asp.net/t/1060173.aspx/1?How+to+disable+cacheWed, 26 Sep 2012 18:12:15 -040010601731519897http://forums.asp.net/p/1060173/1519897.aspx/1?How+to+disable+cacheHow to disable cache <p style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:Arial">I know this question has been asked a dozen times but in all the posts I can't find an answer that works for me.</span></p> <p style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:Arial">&nbsp;</span></p> <p style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:Arial">I am trying to completly disable all cache from a page, so when the user goes back using the browser buttons, there appears the typical sign of &quot;This page has expired&quot;.</span></p> <p style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:Arial">&nbsp;</span></p> <p style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:Arial">&nbsp;So far I've tried the page directive:</span></p> <p style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:Arial">&lt;%<span style="color:blue">@</span> <span style="color:maroon">OutputCache</span> <span style="color:red">Duration</span><span style="color:blue">=&quot;1&quot;</span> <span style="color:red">Location</span><span style="color:blue">=&quot;None&quot;</span> %&gt;</span></p> <p style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:Arial">&nbsp;</span></p> <p style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:Arial">The Meta tags:</span></p> <p style="margin:0cm 0cm 0pt"><span style="font-size:10pt; color:blue; font-family:Arial">&lt;</span><span style="font-size:10pt; color:maroon; font-family:Arial">meta</span><span style="font-size:10pt; font-family:Arial"> <span style="color:red">http-equiv</span><span style="color:blue">=&quot;Expires&quot;</span> <span style="color:red">CONTENT</span><span style="color:blue">=&quot;0&quot;&gt;</span></span></p> <p style="margin:0cm 0cm 0pt"><span style="font-size:10pt; color:blue; font-family:Arial">&lt;</span><span style="font-size:10pt; color:maroon; font-family:Arial">meta</span><span style="font-size:10pt; color:blue; font-family:Arial"> </span><span style="font-size:10pt; color:red; font-family:Arial">http-equiv</span><span style="font-size:10pt; color:blue; font-family:Arial">=&quot;Cache-Control&quot; </span><span style="font-size:10pt; color:red; font-family:Arial">CONTENT</span><span style="font-size:10pt; color:blue; font-family:Arial">=&quot;no-cache&quot;&gt;</span></p> <p style="margin:0cm 0cm 0pt"><span style="font-size:10pt; color:blue; font-family:Arial">&lt;</span><span style="font-size:10pt; color:maroon; font-family:Arial">meta</span><span style="font-size:10pt; color:blue; font-family:Arial"> </span><span style="font-size:10pt; color:red; font-family:Arial">http-equiv</span><span style="font-size:10pt; color:blue; font-family:Arial">=&quot;Pragma&quot; </span><span style="font-size:10pt; color:red; font-family:Arial">CONTENT</span><span style="font-size:10pt; color:blue; font-family:Arial">=&quot;no-cache&quot;&gt;</span></p> <p style="margin:0cm 0cm 0pt"><span style="font-size:10pt; font-family:Arial">&nbsp;</span></p> <p style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:Arial">And the code:</span></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:'Courier New'"><span style="">&nbsp;&nbsp;&nbsp; </span>Response.ExpiresAbsolute = DateTime.Now</span></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:'Courier New'"><span style="">&nbsp;&nbsp;&nbsp; </span>Response.Expires = -1441</span></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:'Courier New'"><span style="">&nbsp;&nbsp;&nbsp; </span>Response.CacheControl = <span style="color:maroon">&quot;no-cache&quot;</span></span></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:'Courier New'"><span style="">&nbsp;&nbsp;&nbsp; </span>Response.AddHeader(<span style="color:maroon">&quot;Pragma&quot;</span>, <span style="color:maroon"> &quot;no-cache&quot;</span>)</span></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:'Courier New'"><span style="">&nbsp;&nbsp;&nbsp; </span>Response.AddHeader(<span style="color:maroon">&quot;Pragma&quot;</span>, <span style="color:maroon"> &quot;no-store&quot;</span>)</span></p> <p style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:'Courier New'"><span style="">&nbsp;&nbsp;&nbsp; </span>Response.AddHeader(<span style="color:maroon">&quot;cache-control&quot;</span>, <span style="color:maroon"> &quot;no-cache&quot;</span>)</span><span lang="EN-GB" style="font-size:10pt; font-family:Arial"></span></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:'Courier New'"><span style="">&nbsp;&nbsp;&nbsp; </span>Response.Cache.SetCacheability(HttpCacheability.NoCache)</span></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:'Courier New'"><span style="">&nbsp;&nbsp;&nbsp; </span>Response.Cache.SetNoServerCaching()</span></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:'Courier New'">&nbsp;</span></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:Arial">But every time the back button is clicked, there appears the previost page.</span></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:Arial">&nbsp;</span></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:Arial">How can I solve that?</span></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:Arial">&nbsp;</span></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><span lang="EN-GB" style="font-size:10pt; font-family:Arial">Thanks</span></p> <p><font color="#0000ff" size="2"><font color="#0000ff" size="2">&nbsp;</p> </font></font> 2007-01-05T13:29:13-05:001520037http://forums.asp.net/p/1060173/1520037.aspx/1?Re+How+to+disable+cacheRe: How to disable cache <p>By OutputCache directive you asking to hold the page in cache for 1 second. You need to remove that if you dont want to cache it.</p> <p>Add these lines in the html meta section</p> <p>&lt;META HTTP-EQUIV=&quot;CACHE-CONTROL&quot; CONTENT=&quot;NO-CACHE&quot;&gt;<br> &lt;META HTTP-EQUIV=&quot;EXPIRES&quot; CONTENT=&quot;0&quot;&gt; </p> <p>and in the page_load write this</p> <p>Response.Cache.SetCacheability(HttpCacheability.NoCache);</p> <p>Thanks&nbsp;</p> <p>&nbsp;</p> 2007-01-05T14:42:29-05:001520142http://forums.asp.net/p/1060173/1520142.aspx/1?Re+How+to+disable+cacheRe: How to disable cache <p>I have already tried removing the OutputCache directive, with the same results. I was expecting that by caching the page for 1 second, after that second it would discard it. I've tried usind another value, but OutputCache doesn't accept non-positive numbers.</p> <p>As I wrote in my previous post I have already used the meta tags and I didn't mention it, but the &quot;response&quot; code is in the page_load too.</p> <p>I also didn't say that I'm using asp.net 2.0</p> <p>Thanks</p> <p>&nbsp;</p> 2007-01-05T15:40:16-05:001520171http://forums.asp.net/p/1060173/1520171.aspx/1?Re+How+to+disable+cacheRe: How to disable cache <p>Setting the OutputCache for 1 second displays the content from cache for one second and after that any new request will get data from server. I tried the code you have given and its displaying the typical page expired message.</p> <p>&nbsp;</p> <p>Thanks&nbsp;</p> 2007-01-05T15:58:20-05:001557949http://forums.asp.net/p/1060173/1557949.aspx/1?Re+How+to+disable+cacheRe: How to disable cache <p>I've created a small hellowWorld type project, implementing the cache disabling method discussed.</p> <p>There are just 2 pages and one of them contains a linkButton to the other. I've built the project and uploaded it to a web server but I still don't have the desired result. I've tried it using explorer 6.0 and mozilla firefox 2.0.</p> <p>&nbsp;If&nbsp;anyone would&nbsp;be so kind, could you have a look at it. You can find it zipped inside the following address.</p> <font size="2"> <p><a href="http://www.bersatil.com/helloworldcache.zip"><font color="#7395c1">http://www.bersatil.com/helloworldcache.zip</font></a></p> <p>Thank you for your time</p> </font> 2007-01-31T18:34:52-05:001560751http://forums.asp.net/p/1060173/1560751.aspx/1?Re+How+to+disable+cacheRe: How to disable cache <p>Hi, rankor20</p> <p>After seriously study your problem, this solution is here: </p> <p><a href="http://www.codeproject.com/useritems/NoCaching.asp">http://www.codeproject.com/useritems/NoCaching.asp</a></p> <p>Hope this helps.</p> 2007-02-02T11:46:22-05:001863270http://forums.asp.net/p/1060173/1863270.aspx/1?Re+How+to+disable+cacheRe: How to disable cache <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Jerome Cui - MSFT</h4> <p></p> <p>After seriously study your problem, this solution is here: </p> <p><a href="http://www.codeproject.com/useritems/NoCaching.asp">http://www.codeproject.com/useritems/NoCaching.asp</a></p> <p></p> </blockquote> &nbsp; <p></p> <p>It failed to work with Firefox. It works with IE perfectly&nbsp;</p> 2007-08-17T12:35:38-04:003793656http://forums.asp.net/p/1060173/3793656.aspx/1?Re+How+to+disable+cacheRe: How to disable cache <p><a href="http://www.codeproject.com/useritems/NoCaching.asp">http://www.codeproject.com/useritems/NoCaching.asp</a></p> <p>This projectis no longer available here. Can i get it from somewhere???<br> </p> <p><br> </p> 2010-04-20T07:17:17-04:003793667http://forums.asp.net/p/1060173/3793667.aspx/1?Re+How+to+disable+cacheRe: How to disable cache <p>hi,</p> <p><a href="http://www.freevbcode.com/ShowCode.Asp?ID=243">http://www.freevbcode.com/ShowCode.Asp?ID=243</a></p> <p>hope this will help you more</p> 2010-04-20T07:23:08-04:004061567http://forums.asp.net/p/1060173/4061567.aspx/1?Re+How+to+disable+cacheRe: How to disable cache <p>I have the same problem with Firefox. Could you solve the problem? I need to disable caching for Firefox.</p> <p>Thanx in advance.<br> </p> <p><br> </p> 2010-09-04T22:37:10-04:004067681http://forums.asp.net/p/1060173/4067681.aspx/1?Re+How+to+disable+cacheRe: How to disable cache <p>I used ajax which solved my problem. Maybe it may help you.<br> </p> 2010-09-08T10:47:26-04:005159983http://forums.asp.net/p/1060173/5159983.aspx/1?Re+How+to+disable+cacheRe: How to disable cache <p>Actually, it's impossible to disable cache at least for ff and chrome (feature of these browsers).</p> 2012-09-26T18:12:15-04:00