0

I have this image URL i got from database.

\\Imagepath\ImageFolder\image.png

but i need to put in a img tag in html to show the image in the page, i try to do this way

<img src='\\Imagepath\ImageFolder\image.png'/>

but the page adds the default url for localhost, ie.

http://localhost:1234/\\Imagepath\ImageFolder\image.png

I need your helpfor trying to get the image from that server URL. I have a lot of images around 6,200 so is not an option to download, i'm show the images in a table.

NOTE: i know the img tag not accept the URL like i have, but maybe you have an idea to do in ASP.NET, i apretiate your help.

NOTE 2:i'm using ASP.NET MVC.

Community
  • 1
  • 1

1 Answers1

1

Paths starting with \\ are UNC paths, they are not URLs. In a browser, you have to use a URL to load an image.

The browser is assuming you've tried to specify a relative URL, and is attempting to add the current URL by default in order to fully qualify it and then make a request to it to get the image.

You need to map the path to a virtual directory in your webserver and then point the image's src property at the URL of that virtual directory.

Alternatively, if that's not a workable solution you could write an MVC action method which takes the name of the image file as a parameter and then loads the image from the UNC path in the background and returns the data in a binary response to the browser.

ADyson
  • 57,178
  • 14
  • 51
  • 63
  • thanks to your question, now i undertand what is the problem with the URL i have, searching about i found this link => https://stackoverflow.com/questions/45859535/html-image-source-from-unc-path ; i hope this help me to solve that. – David Mendez Guardado Oct 22 '19 at 16:21
  • @DavidMendezGuardado yes that's a good idea, although personally I would return the image as a binary response rather than having the overhead of converting to base64. But it's up to you. – ADyson Oct 22 '19 at 16:22