I want intercept all request for image files, but i am not getting a way to do it,
One way is to create an action in MVC controller and return all image files from it,
public HttpResponseMessage Get(Guid id)
{
var path = HttpContext.Current.Server.MapPath(string.Format("/OriginalImages/{0}.jpg", id));
byte[] fileData = File.Exists(path) ? File.ReadAllBytes(path) : new byte[0];
MemoryStream ms = new MemoryStream(fileData);
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new ByteArrayContent(ms.ToArray());
result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
return result;
}
but it does not seems good idea as i noted that image access request completing in 15-20 milliseconds, while direct image access via path takes 5-6 milliseconds.
I tried using Owin Middleware, but it do not get executed on image file requests.
How can i achieve this? I want to increment view count of image file by this.