-1

I'm trying to add a link in a project that will open a tutorial that explain how to use the system. The tutorial is only relevant to those who work in the company so I figured it would be best to place the the tutorial on our company network drive and only redirect to this file from web client. In that way it will also be easy to change the tutorial without reuploading the system.

The problem seems that chrome is blocking me from opening a local file from the web client.

But if I remember correctly there are web sites that can open a local pdf files. so why I can't open the tutorial? It is basically a presentation (I think in flash, not really important) that you can open by opening a html file.

Is there any alternate solution for this? I'm also okay if chrome will ask the user if he is sure that he wants the file to be opened or something like this. But I don't want to add files directly to my project code because it will require reuploading the whole project to only update the tutorial.

I'm using ASP.NET Framework in the backend and Angular in the Frontend.

Sean Goldfarb
  • 329
  • 6
  • 22
  • 2
    You do know that flash support has ended, right? https://support.google.com/chrome/answer/6258784?hl=da – Palle Due Jan 21 '21 at 08:00
  • So maybe it is not flash... it is not important to me, I just know you open it by clicking on a html file, and if I copy and paste the file location to the search bar of the browser it knows to open it up and show what's needs to be shown. – Sean Goldfarb Jan 21 '21 at 08:05
  • 1
  • I tried to do this one but I got an error message in the console: Opening local files is not allowed. As I said chrome is blocking me from doing it. – Sean Goldfarb Jan 21 '21 at 08:13
  • It seems this question has been asked already. [Can Google Chrome open local links?](https://stackoverflow.com/questions/2087894/can-google-chrome-open-local-links) Basically you cannot do this due to security reasons. There is a Chrome extension that removes this restriction, but it's there for good reasons, so I would try to find an alternate solution. – Nino van der Mark Jan 21 '21 at 08:17
  • Does this answer your question? [Open local files(file://) using Chrome](https://stackoverflow.com/questions/28724751/open-local-filesfile-using-chrome) – mbojko Jan 21 '21 at 08:17
  • So is there any alternate solution to this? a way that I could show them the tutorial but without adding it to the project? – Sean Goldfarb Jan 21 '21 at 08:25
  • 2
    I guess you could add a folder to your backend project that is to be treated as source for static content, so its contents would be hosted like from a webserver. Then you can link like you would any online resource. – Fildor Jan 21 '21 at 08:43
  • Thanks, that may help and I will try it, but if I have multiple servers this means that I will have to update the tutorial in each server separately? – Sean Goldfarb Jan 21 '21 at 09:09
  • Well, if the servers are all on different networks - then yes. But you can add a virtual folder to all of the servers that point to the one same folder. If that folder is not on the same network, then you would have to copy that folder - but you would have to do that anyway if the server(s) in question all can't see + use the one folder. So, as long as all the web servers can see that one folder? Then just create a virtual folder for each web site that points to the folder, and that will allow + produce a valid URL to those files. See my post below. – Albert D. Kallal Jan 21 '21 at 18:48

1 Answers1

-4

No person with a brain would use a browser that lets it open local files. You mean you come to my site to watch cat videos and all the while the browser is opening your banking files or stealing your excel sheet marked "my passwords?". not even close! A browser cannot open local files period!!! To high of a security risk.

You can of course EXPOSE a folder to the web server, and then ANY file in that folder becomes part of the web site and MORE important becomes part of the web server "URL" mapping.

So, you can have your typical site (in say inetpup\wwwroot. In that folder then ONLY valid urls to files in that web site folder are allowed.

And say you have some big file server on your network full of files? Well, then you can add to the site what is called a virtual folder.

So, say the web site is on c:\inetpub\wwwroot

So, any valid URL typed in a by a user (or your code launching a web page) is now

http://mysite/default.aspx

The above file of course maps to c:\inetpub\wwwroot\Default.aspx.

So, say you have a folder on the network full of pdf's you want users to see/view/use?

Well, say that folder is: \SERVER5\PpdFileArcive.

So, that folder is NOT part of the web site. What you do is add a virtual folder to the asp.net site. Lets call it MyPdfs

You map MyPdfs to the above \SERVER5\PdfFileArchive

So, now your URL becomes this: http://mysite/MyPdf/help.pdf

So, the browser can NOT look at local files on your computer (and would you actually think that is ok that my web site can rummage around on YOUR local computer? Not!!!!).

So you can have some folder sitting on your local network. And if the web site is on that SAME network, then you can add a virtual folder to the web site. That "external" folder will then become part of the web site and mapped to a web "URL" that will then allow you to say have hyper-links, or even allow the user to type in ANY url like:

http://mysite/MyPdf/HowToCookPotatos.pdf

In fact, in many cases you do NOT want users to type in URL's, and in often you do NOT want the users to be able to type in a url.

Well, keep in mind that code behind (the .net code running on the web server) is really the same as .net desktop code. That code behind can open/read/use any file anyplace on the network - including files on your desktop. But that would assume the web server is on the SAME network as you, and it would assume that say even a desktop program running on ANY computer has rights to YOUR desktop folder. (and that's not the default - I think most desktops have a shared public folder).

So, code behind on that web server can open, read/process any file. But you NOT be able to say use a hyper-link, or say a valid URL to get at those files.

Since a company often does NOT want to expose that big huge pdf folder to the wild and crazy internet? Then what is common done is that you do NOT create a virtual folder, and you do NOT map URL's to that internal company folder. you have the code behind OPEN + READ and then STREAM the file down to the browser. You can google and find 100's of examples - just google stream a pdf to browser for how this works. But again, keep in mind that this trick/suggestion STILL is limited to code behind running on the server being able to directly access and open that file sitting on a folder. That file can be any place on the network as long as the web server has rights to read/open/use such files. Users of the web site will not have any possible URL to type in, but if the code behind has such rights or the ability to open such files, then web code can be written to "dish out" or so called "stream" that file to the browser.

So keep in mind the concpet of a web URL (a valid web path name), and that of code behind that does NOT use URL's to open and read files - but you use plane jane regular windows file path names.

Of course if you have a virtual folder and a URL exposed to end users, then code behind STILL often needs to process/open/copy or do whatever with that URL the user typed in. That's where server.mapPath comes in. it will translate the URL value to a full internal path name.

So Code behind = ALWAYS needs a full valid windows path name. URL -web folders (including virtual folders that point to server folders). These URL's can be used in hyper-links, web navigation, and even allows the user to type in a full valud URL to the given pdf in that folder (but the user will type in a valid URL that resolves to that folder).

So while you can't for all practical purposes have a browser read/get/use local files on a YOUR computer? You can certanly setup a folder on some server (even the web server) that has all those pdf's, pictures or whatever you want. And with a mapped virtual folder, then the Web users can then consume such files.

Or if you want to keep things locked down, don't want users typing in URL's to files that might not belong to them? Then you can of course maintain a list of files say in a database or whatever. And the code behind can read such files 100% directly with a full valid internal path name and then PUSH (stream) that file out to the user.

Here is a example of such code: Stream PDF to browser?

Albert D. Kallal
  • 42,205
  • 3
  • 34
  • 51