'How to clear cache of IFrame using c# Code in asp.net

In my asp.net (Runtime Version 3.5) there is a requirement of displaying Pdf in the middle of the page along with other content.

So in such case I found the solution. for this I used Iframe . But we have to display the pdf on linbutton_click event.

HTML part

<div id='Pdfviewer'>
    <iframe id="ifrDisplay" runat="server" scrolling="auto" width="600" height="700"></iframe>
</div>

C# code part

LinkButton1_click
{
    string pdfUrl = "https://test-folder.com/rxdata//P09/201305240039MA9_000/Data/00000010.pdf";//
    ifrDisplay.Attributes.Add("src", pdfUrl);

}

Here the issue is even if the content of the particular pdf changes, still it loads the pdf of older content. So it is clear this is caching related issue.

Please let me know how to remove the cache due to which still the older content of pdf file is loading.

--Sarthak



Solution 1:[1]

To avoid caching you can use some random number in the URL so that browser does not cache the response.

string pdfUrl = "https://test-folder.com/rxdata//P09/201305240039MA9_000/Data/00000010.pdf"+DateTime.Now();

The second possible option is that who is serving PDF should set the cache to (-1) so that it not get cached in the browser.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 शेखर