Solved

Prevent Caching of Web Pages - How to Test?

Posted on 2008-10-13
6
966 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 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

691 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