I have the following scenario, and I wanted suggestions on what is the best way to handle this. My web app (ASP.NET 2.0 / IIS 6) generates PDF files, and I have a results page with links to those PDFs.
Now, I noticed that if I visit the results page, click on a PDF file (it opens in a new window), then re-generate the PDF file, and click on the same link in the results page, the OLD PDF is shown, instead of the new one. I had to delete the temporary internet files in order to see the new one.
So, since I'm NOT serving an ASPX that actually writes the PDF (and I do not want the Save dialog to show), but straight linking to the PDF file, I want to know what the best way to make sure the user always sees the latest file in the server, not a cached version.
I'm guessing adding no-cache headers is out of the question. But the PDF request would still go through an HTTP handler, so I'd like to know if I should create a specific HTTP handler to intercept requests for PDFs, or if i should do this at the IIS level...however I dont necessarily want to avoid caching ALL PDF's on that site.
Any suggestions? Thanks in advance for the help.
Follow the steps under Adding MIME Types to IIS 5.0 See if pdf is already defined in the list you get after press File Types, otherwise continue following the steps to add it. There is a whole list on that page of various file types to add, for pdf you will want extension pdf and type application/pdf.
Configure an ASP.NET Website on IIS. 1 Step 1: Install IIS and ASP.NET Modules. 2 Step 2: Configure ASP.NET Settings. 3 Step 3: Configure Data Source Settings. 4 Step 4: Configure Application Security. For planning information to review before deployment, see Plan an ASP.NET Website on IIS. For more ...
In this article I will explain with an example, how to implement PDF Viewer in ASP.Net by embedding PDF file on Web Page using C# and VB.Net. The HTML Markup consists of an ASP.Net LinkButton and a Literal control. The below event handler is raised when the View LinkButton is clicked. Here I am making use of HTML OBJECT Tag to embed PDF in browser.
C1 ASP.NET Core's PDFViewer can be used for this purpose. The PDFViewer provides many different options to view a PDF file using its interactive features and user-friendly user interface. PDFViewer is a fast and flexible HTML5 based PDF viewer that allows the user to display PDF files in the web browser.
If your link to the pdf document had a unique querystring appended I believe that would prevent caching. Time in ticks is a good one to use, eg:
string.Format("{0}?t={1}", pdfFileUrl, DateTime.Now.Ticks);
The fact the clearing your temporary internet files gave you the new version shows the browser is the source of the cache. You could turn iis caching off but that wouldn't stop proxies caching the document. If you need to be 100% sure that the user sees that latest version, I suggest using a query string value to cause the url to be different. The query string could be the pdf generation timestamp.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With