question

Lectrician-8959 avatar image
0 Votes"
Lectrician-8959 asked SamWu-MSFT commented

No Cache .PDF files

I have a website hosted on IIS7 on a windows 10 machine. It is not a website as such, there are just a few PDF files hosted there, and the full URL to them is used in a QR codes. Someone scans a QR code, and the PDF opens to view.

I want to ensure if a PDF is amended, when a user scans a QR code, they will receive the latest version of the file, not a copy cached on their phone etc. The PDF files are menus for a restaurant.

I have tried using the output caching option, which creates the web.config file, with the below in it:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<caching>
<profiles>
<add extension=".pdf" policy="DisableCache" kernelCachePolicy="DisableCache" />
</profiles>
</caching>
</system.webServer>
</configuration>

Once this is there, the server gives an internal server error when visiting the URL. Deleting the web.config file restores service.

Do PDF files even get cached?

What is wrong with the web.config file the IIS Server Manager creates when using the "output caching" option?

Thanks :-)

windows-server-iis
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Lectrician-8959

Once this is there, the server gives an internal server error when visiting the URL.

Can you post details about the internal server error?

<add extension=".pdf" policy="DisableCache" kernelCachePolicy="DisableCache" />

There seems to be something wrong with your pdf cache configuration, you can try to configure it by referring to this link: Caching <caching>.

0 Votes 0 ·

Hi. Thanks.

My original question should say IIS10, not 7.

The error message in the logs is a 500.19 error, the error when visiting the URL in the web page is "The page cannot be displayed because an internal server error has occurred." 500.19 does indicate a malformed web.config file, but it is IIS manager that is creating the file.

Looking at the link you gave, it does say that static pages (which I guess a PDF is) has no need to be cached. "Output caching is unnecessary for static files, such as HTML, JPG, or GIF files, and can cause more memory overhead for dynamic ASP.NET or PHP pages that read from a database that changes frequently." The caching is also happening on the server when using this method, it is not preventing the client from caching it locally on their device.

I guess I need to work out how to prevent it being cached on the client side, not the server side. This seems more appropriate: https://docs.microsoft.com/en-us/iis/configuration/system.webserver/staticcontent/clientcache, however, setting this to expires immediately also gives me the 500.19 internal server error until I delete the web.config file.




0 Votes 0 ·
SamWu-MSFT avatar image SamWu-MSFT Lectrician-8959 ·

@Lectrician-8959 Try using failed request tracing to see details about 500.19 error.

0 Votes 0 ·

0 Answers