0

My ASP.Net MVC app is an intranet app, and in the HTML, I put an anchor link to PDF files that are stored on our network. Chrome does not open these files in the browser if you click on the link, however if you copy the link off the webpage and make a new tab, paste the link in, it will open.

Now, both the app and the files are on the same domain so how can I get PDF to open automatically in a new tab? I have looked at the various Chrome extensions, but they don't seem to work. There must be a way to get local/network based files to open in your intranet using Chrome, please don't say I have to resort to awful Internet Explorer!

Any help much appreciated.

Vidar
  • 6,548
  • 22
  • 66
  • 96
  • Possible duplicate of [Cannot open local file - Chrome: Not allowed to load local resource](https://stackoverflow.com/questions/39007243/cannot-open-local-file-chrome-not-allowed-to-load-local-resource) – Kraz Sep 19 '17 at 15:24

3 Answers3

0

Have you tried to use HTML iframe tag to display the PDF? Example:

<iframe id="frameID" style="border:1px solid #666CCC" title="PDF in an i-Frame" src="PDFData.pdf" frameborder="1" scrolling="auto" height="1100" width="850" ></iframe>
Tiago B
  • 1,937
  • 14
  • 34
  • Not overly keen on displaying it in the actual web page - rather just showing it in a new tab, without copy/pasting the link. – Vidar Mar 19 '13 at 08:22
0

Out of date for you, but I recently solved this problem on an apache2 server on ubuntu. I believe it's a matter of security from the client browser- so that a webpage can't open client files maliciously

What solution was

  • mount the network share drive on my web server
  • html point to pdf inside the mounted drive
  • (Optional on Apache) use a .htaccess rule to prevent folder indexing (listing all files/folder)

therefore the webpage was opening its own file, not the clients; so firefox/chrome/et al will allow this to happen

Liam
  • 1
0

The fix should be in your mvc project . Just make sure the action returns FileStreamResult . example:

return new FileStreamResult(new FileStream(filePath, FileMode.Open), MimeMapping.GetMimeMapping(filePath));
Ashi
  • 806
  • 1
  • 11
  • 22