You could write a handler that opens the file on the network using its UNC path and writes its contents to the response using Response.WriteFile
:
<%@ WebHandler Language="C#" Class="Handler" %>
using System.IO;
public class NetworkImageHandler : System.Web.IHttpHandler
{
// Folder where all images are stored, process must have read access
private const string NETWORK_SHARE = @"\\computer\share\";
public void ProcessRequest(HttpContext context)
{
string fileName = context.Request.QueryString["file"];
// Check for null or empty fileName
// Check that this is only a file name, and not
// something like "../../accounting/budget.xlsx"
// Check that the file extension is valid
string path = Path.Combine(NETWORK_SHARE, fileName);
// Check if the file exists
context.Response.ContentType = "image/jpg";
context.Response.WriteFile(path, true);
}
public bool IsReusable { get { return false; } }
}
Then you set the image src
to the handler url:
<asp:Image runat="server" ImageUrl="~/NetworkImageHandler.ashx?file=file.jpg" />
Be very strict about checking the input, don't create a handler that would allow someone to open just any file on your network. Restrict access to a single folder, only give the worker process access to that folder and check for valid file extensions (e.g. jpg, jpeg, png, gif).
This is a rather simple example, don't use it in production without testing.
For alternative ways to write content to the response, and more example code, see: