Want to disable flash caching? - asp.net

I have a .swf flash gallery that loads pics from a XML file
the probelm is when I modify the XML the modifications do not reflect on the flash till I delete the browsing cache from the browser
I tried to disable caching using code like this
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.AddHeader("Pragma","no-cache");
Response.Expires = -1;
but not working
is there any workaround for this ?
thanks

You could add a parameter to you XML file request. Something like "pictures.xml?dummy=[timestamp]". In that case, your browser thinks you are requesting a new file.
Hope this will help. :)

Related

Simple question about style sheet source files [*.css?ver=]

What does appending a query string to the end of a style sheet do? I often see:
some-stylesheet.css?ver=1.2.3
Thanks.
Usually people use it to prevent caching of the CSS file.
It could also be used by the server software (Apache, for example) to load a specific version of the CSS based on the string.
Adding a new query string forces the browser to reload the file instead of using a cached one.
it helps with caching, if you append a query string the browser treats it like a new file, that way when you make changes they are shown immediately, not after you clear the browser cache
This is used in order to workaround browser caching while developing. If you increment that number in your HTML, browser will suppose it's a new file that he has not see ever before and will render the last version of it.
Problably they want to show you the newest version of the CSS, without caché of the browser. So using a parameter its solved.

Aspx cache problem?

When I update a js file in my asp.net project, I refresh the browser and the change shows up as expected. If I change a css file or an .aspx file, the change does not show in the browser. Not when I clear the browser's cache, not when I restart IIS (iisrestart). What could this possibly be?
PS. I have tried chrome and firefox
Your browser loves to cache files such as CSS, JS and XML docments.
Do a "hard refresh" to tell your browser to download everything again.
Typically, it's CTRL-F5
You can also append a random number to the end of the file name so that it's never the same and the browser will snatch it up each time.
I have observed weirdness like this in chrome, but not firefox.
When you open it in firefox with firebug, are you seeing a 304 code? That might help separate server side issues from client issues.
I've had this problem a couple of times. Adding a random querystring value on the end of the URL for CSS seemed to fix things. So if your URL was /css/styles.css, just put in some code to add a random number on the end so the URL looks like /css/styles.css?random=2345.

IE not showing PDFs with caching disabled

I've been asked to implement a security requirement that we instruct browsers not to cache sensitive data. This is all fine for the ASPX content using the standard instructions:
Response.Expires = -1;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
However when I set these headers for PDF downloads, IE8 won't show the PDF (haven't tried other IE versions yet, kinda moot, I need it working on all of them, even IEfreaking6). Seems to work in firefox 4 beta, but I haven't double checked that it's definitely not caching it. Here is the abridged version of the code I'm using to serve the PDFs:
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.Buffer = true;
//This stops the PDFs from being viewed :(
//Response.Expires = -1;
//Response.Cache.SetCacheability(HttpCacheability.NoCache);
//Response.Cache.SetNoStore();
Response.ContentType = mime;
Response.AddHeader("Content-Disposition", disposition);
Response.BinaryWrite(file);
Response.End();
Where in the case of PDFs the mime type is set to:
private const string mimeTypePDF = "application/pdf";
The disposition is set to:
var disposition = String.Format("{0};filename=\"{1}\"", SendInline ? "inline" : "attachment", Path.GetFileName(filename));
I'm going to play-around a bit more, maybe forcing them to download as mimetype "application/octet-stream" might work, but that would stop the nice open PDF's in a new browser window from working.
Has anyone had any success with preventing IE from caching PDFs from the server side and successfully displaying them?
Just to give a clear example about what happens. In one scenario user's can select a bunch of reports from a list, these are compiled into a PDF and the PDF is shown in a new browser window. With the caching enabled the browser window opens, but remains resolutely blank.
I've had the same problem with IE a few years ago and let is cache since I didn't have a requirement to disallow it.
However, since users are free to save a PDF document once the browser shows it, how do you plan on prevent them from do that?
Not that this will solve your problem but when sending physical files you should Response.TransmitFile instead of BinaryWrite. It's much faster and more efficient in terms of memory utilization since you don't need to load the entire file in memory before sending it.
Looks like this issue has been resolved in IE9.
I can now successfully execute the following:
Response.Expires = -1
Response.Cache.SetNoStore()
Response.AppendHeader("Pragma", "no-cache")
Response.ContentType = "application/pdf"
Response.BinaryWrite(myByteBuffer)
Response.Flush()
Response.Close()
Enjoy!
I'm going to say it's not currently possible, nothing I tried seemed to get it to work. Try and get your customers to use firefox instead! :)
I also believe it's a bug in Internet Explorer. I was setting the cache-control header to no-cache and having the same problem. Also note that in Internet Options > Advanced > Security there's a 'Do not save encrypted pages to disk' option that could affect it.
Removal of the cache-control header from the response sorted out my issue. I also then tried checking the above mentioned option, and it seemed to work even better for me. Iinstead of storing the PDF in %LocalAppData%\Microsoft\Windows\Temporary Internet Files, it actually caused IE8 to issue a dialog allowing me to choose where to save it (which is actually what I wanted in my case).
This issue of showing pdf (and other document types) in-browser with the use of the no-cache header has been filed as a bug to Microsoft: http://support.microsoft.com/kb/316431. When you try to open a document in this case, IE tries to read it from cache, but it isn't there.
Unfortunately, the folks at M$ said this "works as designed" and users should not use the no-cache header... go figure.

Why does Response.Redirect close my browser window instead of redirecting?

For whatever reason when I use Response.Redirect the window just closes out instead of navigating to the given URL, here is the code.
if (mode == "print")
{
error_code.Text = "";
//thumb.Src = file_loc + "source/" + "certificate_thumbnail.jpeg";
link.HRef = "Certificates/" + u_name + ".pdf";
link.Visible = true;
Response.Redirect("http://xx.xxxxxxxxxxxxx.xx.gov/cert/Certificates/" + u_name + ".pdf");
}
(I removed the url for security purposes given who my client is...)
Maybe the Adobe Reader plugin is crashing the browser?
The problem is due to you opening an aspx page which contains the redirect to .pdf. As the aspx is pre-compiled when its opened by IE it EXPECTS text/html to come back - however as you've redirected its actually receiving application/pdf so IE craps itself and closes. Try it in firefox - works fine I bet.
I actually have the exact same problem at the moment and have yet to get a workaround. However check out this link https://stackoverflow.com/questions/400010/ie-closing-just-opened-popup-window theres some good stuff in there that may help.
Use Firebug in Firefox or a http debugging proxy like Fiddler for Internet Explorer to see exactly what the response of the server contains. Maybe the response isn't a PDF, but text/html which contains a Javascript window.close().
My guess is, that the code you posted isn't being executed for some reason and something else is happening.
What ever you have as your default PDF reader is likely causing this.
If you do
Response.Redirect("http://www.google.com");
What happens?
Try redirecting to a PDF that you know is valid. By searching google for PDF, I was able to find this PDF (http://www.utoronto.ca/cip/sa_ArtGt.pdf). So, if you redirect to that link does it still close the browser window? If it doesn't it's most likely related to your specific PDF file. If there's something wrong with your PDF File, try to regenerate it, if at all possible.

ASP.NET Refresh the page after uploading image

I have an ASPX page where I am uploading an image to server for on a serverside button click event. In my page, it will show the available image if it exists. When I upload an image, it will replace the old one with the new one. Now after uploading also the same image is getting displayed. How can tackle this? I used window.location.reload() javascript function to refresh, but then it is not working. It is posting the page again.
This is my code
Do UploadImage(studentId,mode); // Function to upload image
StringBuilder sbc = new StringBuilder();
sbc.Append("<script language='javascript'>");
sbc.Append("alert('Upload process completed successfully!');");
sbc.Append("window.location.reload()");
sbc.Append("</script>");
HttpContext.Current.Response.Write(sbc);
It's being cached in the browser. To overcome this - alter the url of the image. This can be done by including a timestamp, version number, or guid in the image file name.
Your browser is probably caching the image. Either disable caching on the image or set up proper caching responses.
You can reload from the server side
Response.Redirect(Request.URL)
A useful tool to debug this is fiddler. As others already suggested it's likely that the browser caches the old version of the image. If you are using IIS you can change the cache policy so that the browser always check for a newer version of the image.

Resources