The ASP.NET Image control explicitly represents the <img> in HTML. As a result, you can only get the image in the HTML document by specifying the URL of the content of the image that you want to insert on the page.
<img src="images/picture.png" />
This means that you need a mechanism to request an HTTP request with an image resource and return a response containing binary image data.
With the ASP.NET Web API, this becomes a trivial operation to implement:
public HttpResponseMessage GetImage(string username) { DataClassesDataContext db = new DataClassesDataContext(); usertable thisuser = db.usertables.FirstOrDefault( p => p.username == username); if (thisuser == null) { return new HttpResponseMessage(HttpStatusCode.NotFound)); } // Create a stream to return to the user. var stream = new MemoryStream(thisuser.picture.ToArray()); // Compose a response containing the image and return to the user. var result = new HttpResponseMessage(); result.Content = new StreamContent(stream); result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg"); return result; }
If you cannot use the web API, you will have to implement an HTTP handler to do the same job.
On the ASP.NET page, you will need to set the ImageUrl property to the address configured for your controller / handler, including the username as part of the URL.
source share