public void ProcessRequest(HttpContext context) { HttpRequest Request = context.Request; HttpResponse Response = context.Response; byte[] data = null; string mediaName = ""; int frameId = DataAccess.IntOrZero(Request.QueryString["frame"]); int contentId = DataAccess.IntOrZero(Request.QueryString["content"]); try { Video video = new Video(frameId); VideoAlternative va = new VideoAlternative(video, contentId); if (va.ContentId != 0) { data = HttpRuntime.Cache.GetOrAddAbsolute( va.CacheKey, () => { Content content = new Content(va.ContentId); if (content.ContentId == 0) return null; mediaName = content.Name; return content.Data; }, DateTime.Now.AddMinutes(video.CacheInterval) ); } } catch (Exception ex) { throw new HttpException(500, ex.Message); } if (data == null) { throw new HttpException(404, "File is empty"); } else { string mimeType = null; try { if (null == (mimeType = MimeTypeParser.GetMimeTypeRaw(data))) { if (null == (mimeType = MimeTypeParser.GetMimeTypeFromRegistry(mediaName))) { if (null == (mimeType = MimeTypeParser.GetMimeTypeFromList(mediaName))) { mimeType = "application/octet-stream"; } } } } catch { mimeType = "application/octet-stream"; } Response.ContentType = mimeType; Response.AddHeader("Content-Disposition", string.Format( "attachment; filename=\"{0}\"", mediaName )); Response.AddHeader("Content-Length", data.Length.ToString()); } Response.BinaryWrite(data); Response.Flush(); }