Solved

Prevent Caching of Web Pages - How to Test?

Posted on 2008-10-13
6
965 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Suggested Solutions

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
A phishing scam that claims a recipient’s credit card details have been “suspended” is the latest trend in spoof emails.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

730 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