Solved

Prevent Caching of Web Pages - How to Test?

Posted on 2008-10-13
6
962 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

791 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