In the web site I develop, when a link is clicked, I open a new browser window showing a pdf file. It worked in all browsers except IE 8. IE 8 was showing empty browser window. When I checked, the file was downloaded by the browser, but the browser somehow wasn't showing the pdf file. This bugged me for a long time, and finally it got solved by a colleague. I wanted to share the solution here so others don't have to go through the pain I went through.
Asked
Active
Viewed 1,076 times
0
-
I don't see why you give -1. I just try to help. – neo Jul 29 '13 at 14:00
-
I did not. I encouraged him to share. – PiLHA Jul 29 '13 at 14:09
1 Answers
2
In the web site, we disabled caching in order to stop people going backwards using the browser back button.
HttpCacheability.NoCache
IE 8 requires any file that is gonna be displayed to be saved in a temporary file before being shown. Disabling caching interrupted saving to a temporary file. Even though the browser downloaded the file successfully, since it couldn't save the file, it didn't show the pdf content or any other document which is shown using active x. We learned that this is an IE 8 bug and it got fixed in IE 9.
Changing the caching to private fixed the issue.
Response.Cache.SetCacheability(HttpCacheability.Private);
Response.ClearHeaders();
Response.ContentType = "Application/pdf";
Response.WriteFile(path);

neo
- 1,952
- 2
- 19
- 39
-
Never, ever, use Response.End(). See http://stackoverflow.com/questions/1087777/is-response-end-considered-harmful – Rake36 Jul 29 '13 at 14:07
-
1Yes, but if someone cuts/pastes your answer, they will be causing problems for themselves later. – Rake36 Jul 29 '13 at 14:12