Click here to Skip to main content
15,885,925 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
Hi,

MVC 4 C# app, I need to allow users to access files from folders that are out the virtual directory, files are created by another app every month.

1. I do not want user see physical path of files like

<a href="C:\temp\7204\bike racks.txt" target="_blank">file1</a>


Could you help to set up access to physical path as virtual path?
Posted

1 solution

Technically you can do that with file:// protocol, but with one condition: this url will point to a local resource - with othe words a resource visible from client side. Sometimes you might need to do that, for example in an enterprise environment. But in general, when you don't know anything about the client, this would be nonsense.

So let's imagine this second scenario. Than you probaly have a web serves. And let's interprete your question as if you would like this url to point to a server resource. At this point having C:\ and so on makes no sense. Your url needs to be a proper absolute or relative url.

As you mentioned MVC, create a controller like GetServerResource that accepts file path as parameter and returns FileResult with the proper content.

But keep following good in mind: deliver only preciselly controlled content. Apply whitelists or other methods. Otherwise anybody could get every file from the server.

Read also this one: http://technet.weblineindia.com/web/securely-serve-file-in-asp-dot-net-mvc/2/[^]
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 25-Nov-14 15:50pm    
5ed.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900