public void StartAsyncTask(object workItemState) { IKernel kernel = KernelManager.GetKernel(); IConfig config = kernel.Get <IConfig>(); IPathHelper pathHelper = kernel.Get <IPathHelper>(); FullPathCleaner cleaner = new FullPathCleaner(s => Context.Server.MapPath(s)); string localPath = cleaner.CleanPath(Context.Request.Url.AbsolutePath); string repoFilePath = pathHelper.ConvertMdUriToLocalPath(Context.Request.Url.AbsolutePath, s => cleaner.CleanPath(s)); string fileToReturn = File.Exists(localPath) ? localPath : repoFilePath; // see if the file exists, if so we need to write it to the response if (File.Exists(fileToReturn)) { var objImage = System.Drawing.Bitmap.FromFile(fileToReturn); MemoryStream objMemoryStream = new MemoryStream(); objImage.Save(objMemoryStream, System.Drawing.Imaging.ImageFormat.Png); byte[] imageContent = new byte[objMemoryStream.Length]; objMemoryStream.Position = 0; objMemoryStream.Read(imageContent, 0, (int)objMemoryStream.Length); Context.Response.ContentType = "image/png"; Context.Response.BinaryWrite(imageContent); } else { Context.Response.StatusCode = 404; } Completed = true; Callback(this); }