Reputation: 588
How to load image file from physical path with out create virtual directory? I use C# code behaind and image source is physical path? How tio convert C:\Folder\imageName.jpg to file:///C:/Folder/imageName.jpg
Upvotes: 3
Views: 2981
Reputation: 1038720
You need to use a controller action to serve that image:
public ActionResult MyImage()
{
return File(@"C:\Folder\imageName.jpg", "image/jpg");
}
and in your view invoke this controller action to show the image:
<img src="@Url.Action("MyImage", "SomeController")" alt="myimage" />
The reason for this is because client browsers cannot access arbitrary files located on the server. If this image is not inside the virtual directory it cannot be referenced by a client. So it is the server that needs to expose it.
Upvotes: 12