?
Solved

Prevent Caching of Web Pages - How to Test?

Posted on 2008-10-13
6
Medium Priority
?
967 Views
Last Modified: 2010-04-21
My ASP.NET 1.1 application has a problem with some users' browsers caching pages that postback to them selves. I want to implement the solution(s) posted in this Question: http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_21935367.html.

Is there any way to test and prove that the solution(s) posted will correct my problem in a Test Environment without just putting it into Production and waiting for customer feedback? I found I can "reproduce" the problem by setting IE to Never check for new versions but, so far, that seems to completely override the suggested solutions. Thank you for your assistance.

Also, when I tried adding the following:

  <meta http-equiv="Expires" CONTENT="0">
  <meta http-equiv="Cache-Control" CONTENT="no-cache">
  <meta http-equiv="Pragma" CONTENT="no-cache">

they didn't appear in my html when I viewed the source. Is that expected with these meta tags?
0
Comment
Question by:ZekeLA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 28

Accepted Solution

by:
strickdd earned 225 total points
ID: 22703981
I use this code in a production environment to prevent cacheing. It will for a page refresh everytime.
protected void Page_Load(object sender, EventArgs e)
{
System.Web.HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddYears(-1));
System.Web.HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
System.Web.HttpContext.Current.Response.Cache.SetNoStore();
System.Web.HttpContext.Current.Response.Cache.SetNoServerCaching();			System.Web.HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
 
}

Open in new window

0
 
LVL 27

Expert Comment

by:Sammy Ageil
ID: 22705285
The meta tags should appear in source when you view it. if you use strickdd's solution you will not need to add any other meta tags to your html. the server will take care of all caching issues.
since your product is ready for production, I would use the code provided by strickdd and in a module instead of writing it to the page load of every page
 
0
 
LVL 28

Expert Comment

by:strickdd
ID: 22706446
If you have a masterpage, you can just include it in the page load of the mastpage if that works better.
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 1

Author Comment

by:ZekeLA
ID: 22707074
Thank you all for the suggestions. I ran into a problem with one page which returned a PDF file to the user using Content-Disposition [attachment; filename="MyFileName"]  but I just needed to call Response.ClearHeaders() firs.

However, I'm still not sure I've fixed the problem. I added the following code to Application_BeginRequest:

         Response.Cache.SetCacheability(HttpCacheability.NoCache)    ' Same as next three options:
         'Response.Expires = -1                                      '  - Expire Immediately
         'Response.AddHeader("pragma", "no-cache")
         'Response.CacheControl = "no-cache"                         '  - Set HTTP/1.1 protocol so proxy servers or
         '                                                           '    other cache mechanisms will not cache pages
         Response.ExpiresAbsolute = DateTime.Now.AddDays(-2)         ' Subtract two days instead of one in case of Int'l Date Line
         Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches)   ' Set HTTP/1.1 directive

When I look at the rendered page output using my browser, however, I don't see any additional meta tags. Is that correct? Do I need to look at IIS configuration?

Lastly, none of the suggestions answer the primary questions: How can I test and / or validate that the changes are working? Everywhere on the web, you can find similar suggestions. But I've yet to see how to actually test this without putting it into production and hoping that it fixes any customer issues. Can anyone answer that part of the question?
0
 
LVL 27

Assisted Solution

by:Sammy Ageil
Sammy Ageil earned 150 total points
ID: 22725500
If you write to the Response Object, the tags will not be shown in the html
to test the cache, just drop a label on any of the pages you have and testing it using one of the DateTime.Now.ToString(); then refresh the page, if its cached the label value will not change "Keeps the initial DateTime value"




0
 
LVL 1

Author Closing Comment

by:ZekeLA
ID: 31505595
I've implemented most of strickdd's solution and haven't had negative user feedback yet.
Sammy1971 answered one of my nagging questions.
I didn't really get an answer on how to test the caching. In the real world, this is dependent on the user's ISP and other servers between them and my web server so I'll just have to rely on user feedback if the problem still continues.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question