I have a shared path \\mynetworkshare\myfolder
which has images stored.
I have a domain user mydomainuser
which was granted with read access to files in that path
I hosted website on IIS. I created a Virtual Directory within my IIS Site with an Alias myphotos
pointing to the Physical path \\mynetworkshare\myfolder
. I have also clicked on Connect as...
button in the Add Virtual Directory
dialog box and provided my mydomainuser
credentials.
I clicked on the newly created virtual director myphotos
and click on Content View in the right pane. I'm able to view all my photos within IIS. From this, I assume the setup of virtual directory to my shared drive is correct.
Now, the question is how do I access this Virtual Directory or Files in it from my code?
I have tried below
var filePath = Server.MapPath("~/myphotos/" + "myimage.jpg");
When I write the filePath to a log file, I see it is trying to map to a physical folder setup within my website folders.
Instead of pointing to
\\mynetworkshare\myfolder\myimage.jpg
it is pointing to
d:\wwwroot\inetpub\mywebsitefolder\myphotos\myimage.jpg
I know Server.MapPath
resolves to a physical path of hosted site but I wonder if it behaves the same with my virtual directory.
Or Do I need to let ASP.Net know somehow that myphotos
is a virtual directory created on IIS? Or Am I on the wrong path to get files? Do I need to write code something different?