0

I developed to .net core mvc Web project. But When I tried to display PDF on web browsers(ie: Chrome, Edge, explorer, firefox..) first I save pdf as a "myfirstlist.pdf", then I updated pdf as a same name "myfirstlist.pdf" but my document changes couldnt reflected. Is that general cached problem ?

My Action Pdf viewing this:

 [HttpGet]
 public PhysicalFileResult OnGetDownload(string fileName)
 {
 string downloadPath = Path.Combine(Directory.GetCurrentDirectory(), @"C:\", fileName);
  return new PhysicalFileResult(downloadPath, "application/pdf");
 }
hkyaaa
  • 100
  • 9
  • Hi, did you mean that you have a local pdf file and you make it show in the browser, and then you created a new different pdf but with the same name as the old one and replaced that old one. And you showed this file in the browser but in the browser showed the content of the older pdf? – Tiny Wang Aug 09 '21 at 02:36
  • yes, but my pdf load and display from server side. Not locally have. but still I couldnt find a solution, I tried some similar problems ie: IIS caching problem [this link](https://stackoverflow.com/a/16555057/11013847) , but I have a doubts , because If I had prevent all cache mechanism User Authentication ande Authorization info may be lost ? Today , still I have searching a solution.. @TinyWang – hkyaaa Aug 09 '21 at 05:13
  • 1
    I haven't test yet but I assume it results from cache. I share my idea as I used to use it to solve the cache issue, that is add a timestamp in the request url to make each request are unique to avoid cached load. Code sample is like : `var getTimestamp=new Date().getTime(); if(url.indexOf("?")>-1){url=url+"&timestamp="+getTimestamp}else{url=url+"?timestamp="+getTimestamp } return url; }` – Tiny Wang Aug 09 '21 at 05:24
  • First of all thank you for your reply, should timestamp request parameter be in my parameter like fileName? I am trying now and it giving me **404 not found error**. my webbrowser link like this: http :/ /mywebsite.com/myprojectModule/myView/OnGetDownload?fileName=\\192.168.x.yy\MyShareFolder\MyDocs\myfirstlist.pdf?timestamp=1628486956405 @TinyWang – hkyaaa Aug 09 '21 at 05:41
  • http :/ /mywebsite.com/myprojectModule/myView/OnGetDownload?fileName=\\192.168.x.yy\MyShareFolder\MyDocs\myfirstlist.pdf&timestamp=1628486956405 try this? – Tiny Wang Aug 09 '21 at 05:51
  • 1
    replace the '?' to '&' – Tiny Wang Aug 09 '21 at 05:51
  • It looks like a open the link , thanks! But now, I will try to cache problem. @TinyWang – hkyaaa Aug 09 '21 at 06:05
  • Can add timestamp in the url solve your no-update-pdf issue? Does the issue still exist? – Tiny Wang Aug 09 '21 at 06:19
  • I finish testing now, and your suggestion is solved my problem, thanks, you save my day – hkyaaa Aug 09 '21 at 07:23
  • Thanks for your response and I'm glad to hear it worked for you. I sum up the solution below, could you pls accept it as the answer? Many thanks : ) – Tiny Wang Aug 09 '21 at 07:30

1 Answers1

1

To sum up the comment here, I assume this issue results from cache, so I think we can add a timestamp in the url to make each request be unique to avoid cache.

Like this:

var getTimestamp=new Date().getTime();
url = "localhost:port/getpdf?your_param=xxx&timestamp="+getTimestamp;
Tiny Wang
  • 10,423
  • 1
  • 11
  • 29