How to provide a hyperlink to file without revealing path?

cdakz
cdakz used Ask the Experts™
on
I need to provide an href / hyperlink in a web browser to a file, so that the user can open/download it, but NOT provide the full path to the file (for security reasons).

What's the best way to do this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jason C. LevineDon't talk to me.
Commented:
Link to a server-side script of some sort that includes the file from another location and sends it back to the user.

Something like this:

http://www.yoursite.com/downloadafile.php

$file_url = 'http://www.yoursite.com/dont/browse/to/this/file.exe';
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary"); 
header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\""); 
readfile($file_url); 

Open in new window

Author

Commented:
I get the gist, but am familiar with asp.net/c#, so the php isn't clear.

Suggestion on how to do this in C# on ASP.NET? (Sorry I didn't say so in the beginning).
Jason C. LevineDon't talk to me.

Commented:
Sorry, I don't work on Windows.  I will add those topics to your question so those Experts will see it.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Top Expert 2016

Commented:
use a virtual directory. http::\\sitename\path can point anywhere on that server.
Commented:
Jason C. Levine's suggestion pointed me in the right direction, even though it was from the LAMP world. I had in my head to somehow fool an <a href... tag to pull this off, which was wrong.

As it turns out, this is almost trivially simple in the ASP.NET MVC world (after looking in the right direction).

Here are 2 references if anybody else wants to know how to implement this using ASP.NET MVC:
www.prideparrot.com/blog/archive/2012/8/uploading_and_returning_files#how_to_return_a_file_as_response

MSDN's FileResult documentation
Jason C. LevineDon't talk to me.

Commented:
Thanks, cdakz.  Happy that I got you looking in the right direction.

Author

Commented:
Selected my solution because it was the ASP.NET MVC solution.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial