Solved

How can I ensure a .aspx page is NOT loaded from cache?

Posted on 2012-04-02
4
243 Views
Last Modified: 2012-06-27
I have a webpage that will return wrong information if the image is pulled from cache.  Is there a way to make sure that my .aspx page is NOT served up from the browsers cache?
0
Comment
Question by:tprofits
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
whosbetterthanme earned 500 total points
ID: 37798211
There are a few tricks to this, and none of them are completely bullet proof but here are some things to try:

'on the server side
<% Response.CacheControl = "no-cache" %>
 <% Response.AddHeader "Pragma", "no-cache" %>
<% Response.Expires = -1 %>

'On the client side
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<meta http-equiv="refresh" content="60" />

Also, another trick others use is to attach a bogus dynamic parameter to the URL such as:

Response.Write("http://myurl.com/myscript.aspx?id=" & now())

This way everytime the url is written, it's different.
0
 

Author Comment

by:tprofits
ID: 37798302
I will try this in a few hours.  Thank you!
0
 
LVL 5

Expert Comment

by:Vishal Kedar
ID: 37800251
Add below page directive

<%@ OutputCache Duration="60" VaryByParam="None" %>
0
 

Author Closing Comment

by:tprofits
ID: 37804502
I used Response.Write("http://myurl.com/myscript.aspx?id=" & now()).  Worked nicely.  Thanks!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

773 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