1

i had an asp.net application which dynamically generates pdf files on click of a button based on some data in an aspx page.

This worked absolutely fine with IE8, but now in IE10, users always get the cached version, and does not get the latest pdf, and everytime the user has to clear temperory internet files, to get the latest versions.

This is driving me nuts! please help!

Please note: F5, ctrl+F5, changing IE cache property to load new page everytime isn't an option, since I cannot ask every user to do that!

I write it to the crystal report template and export it as a pdf to a local folder on the server, and then open it in the browser using javascript (window.open())

relevant code below:

     string fileName = "PCT_" + this.ContractNoTextBox.Text.Trim() + "_" + this.ContractTypeList.SelectedValue[0] + "_" + this.VersionTextBox.Text.Trim();

            string physicalFilePath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "ExportData\\" + fileName + ".pdf";
            //Delete the file if it exists
            if (File.Exists(physicalFilePath))
            {
                File.Delete(physicalFilePath);
            }

            reportdocument.ExportToDisk(ExportFormatType.PortableDocFormat, physicalFilePath);
            string filePathToExport = Request.Url.AbsoluteUri.Remove(Request.Url.AbsoluteUri.LastIndexOf("/")) + @"/ExportData/" + fileName + ".pdf";

            string openFileScript = "window.open('" + filePathToExport + "', '_blank');";

PS: this works actually when I'm debugging on localhost, doesn't work only when I deploy it on the server.

Plzzz help!!

  • You could set the cache expiration (this is a header of the response) to a date in the past. Adding a cache buster to the requested url will also work. – Prusse Nov 07 '14 at 15:01

1 Answers1

0

the best solution is this I guess, works everywhere! Right way to have ASP.NET / IIS NOT cache PDF files

but I still wonder what difference does it make when I debug in visual studio!

Community
  • 1
  • 1