Solved

Prevent Caching of Web Pages - How to Test?

Posted on 2008-10-13
6
959 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
  • 2
  • 2
  • 2
6 Comments
 
LVL 28

Accepted Solution

by:
strickdd earned 75 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
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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
Sammy earned 50 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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 …
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now